Skip to content

Commit 1b5aac1

Browse files
committed
搞定磁盘加密对配置读取的影响
1 parent b0f5237 commit 1b5aac1

8 files changed

Lines changed: 91 additions & 37 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.notxx.notification;
2+
3+
import android.app.Notification;
4+
5+
import de.robv.android.xposed.XposedHelpers;
6+
7+
public class MIUIFix extends Notification.Style {
8+
private final Notification.BigTextStyle bigText;
9+
private final Notification.MessagingStyle messaging;
10+
11+
public MIUIFix() {
12+
bigText = (Notification.BigTextStyle)XposedHelpers.newInstance(Notification.BigTextStyle.class);
13+
messaging = (Notification.MessagingStyle)XposedHelpers.newInstance(Notification.MessagingStyle.class);
14+
}
15+
16+
// @Override public RemoteViews makeContentView(boolean increasedHeight) { return bigText.makeContentView(increasedHeight); }
17+
// @Override public RemoteViews makeBigContentView() { return messaging.makeBigContentView(); }
18+
// @Override public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { return messaging.makeHeadsUpContentView(increasedHeight); }
19+
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.notxx.xposed;
2+
3+
import android.util.Log;
4+
5+
import java.io.File;
6+
7+
import de.robv.android.xposed.XSharedPreferences;
8+
9+
import com.oasisfeng.nevo.xposed.BuildConfig;
10+
11+
public class DeviceSharedPreferences {
12+
public static XSharedPreferences get(String packageName) {
13+
File file = new File("/data/user_de/0/" + packageName + "/shared_prefs/" + packageName + "_preferences.xml");
14+
XSharedPreferences prefs = new XSharedPreferences(file);
15+
if (BuildConfig.DEBUG) Log.d("DeviceSharedPreferences", "file " + file + " " + file.exists());
16+
return prefs;
17+
}
18+
}

src/main/java/com/oasisfeng/nevo/decorators/wechat/MessagingBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,10 @@ private static Bundle toBundle(final Message message) {
391391

392392
interface Controller { void recastNotification(String key, Bundle addition, WeChatDecorator.ModifyStatusBarNotification... modifies); }
393393

394-
MessagingBuilder(final Context context, final Context packageContext, final SharedPreferences preferences, final Controller controller) {
394+
MessagingBuilder(final Context context, final Context packageContext, /* final SharedPreferences preferences, */final Controller controller) {
395395
mContext = context;
396396
mPackageContext = packageContext;
397-
mPreferences = preferences;
397+
// mPreferences = preferences;
398398
mController = controller;
399399
mUserSelf = buildPersonFromProfile(packageContext);
400400

@@ -418,7 +418,7 @@ void close() {
418418
}
419419

420420
private final Context mContext, mPackageContext;
421-
private final SharedPreferences mPreferences;
421+
// private final SharedPreferences mPreferences;
422422
private final Controller mController;
423423
private final Person mUserSelf;
424424
private final String mPrefKeyMentionAction;

src/main/java/com/oasisfeng/nevo/decorators/wechat/WeChatDecorator.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ else if (conversation.getType() == Conversation.TYPE_UNKNOWN)
315315
final boolean is_group_chat = conversation.isGroupChat();
316316

317317
extras.putBoolean(Notification.EXTRA_SHOW_WHEN, true);
318-
if (mPreferences.getBoolean(mPrefKeyWear, false)) n.flags &= ~ Notification.FLAG_LOCAL_ONLY;
318+
// if (mPreferences.getBoolean(mPrefKeyWear, false)) n.flags &= ~ Notification.FLAG_LOCAL_ONLY; // TODO
319319
setSortKey(n, String.valueOf(Long.MAX_VALUE - n.when + (is_group_chat ? GROUP_CHAT_SORT_KEY_SHIFT : 0))); // Place group chat below other messages
320320

321321
MessagingStyle messaging = mMessagingBuilder.buildFromExtender(conversation, evolving, title, getArchivedNotifications(getOriginalKey(evolving))); // build message from android auto
@@ -430,12 +430,12 @@ private boolean isWeChatTargeting26OrAbove() {
430430
@Override public void onCreate(SharedPreferences pref) {
431431
super.onCreate(pref);
432432

433-
overrideContentView = pref.getBoolean("decorator_wechat.miui_fix", false);
433+
overrideContentView = pref.getBoolean(prefKey + ".miui_fix", true); // TODO
434434

435-
loadPreferences();
436-
mPrefKeyWear = getString(R.string.pref_wear);
435+
// loadPreferences();
436+
// mPrefKeyWear = getString(R.string.pref_wear);
437437

438-
mMessagingBuilder = new MessagingBuilder(getAppContext(), getPackageContext(), mPreferences, this::recastNotification); // Must be called after loadPreferences().
438+
mMessagingBuilder = new MessagingBuilder(getAppContext(), getPackageContext(), /* mPreferences, */this::recastNotification); // Must be called after loadPreferences().
439439
}
440440

441441
@Override public void onDestroy() {
@@ -445,25 +445,25 @@ private boolean isWeChatTargeting26OrAbove() {
445445
super.onDestroy();
446446
}
447447

448-
private void loadPreferences() {
448+
/* private void loadPreferences() {
449449
Context context = getPackageContext();
450450
if (SDK_INT >= N)
451451
context = context.createDeviceProtectedStorageContext();
452452
//noinspection deprecation
453-
mPreferences = context.getSharedPreferences(getDefaultSharedPreferencesName(context), Context.MODE_MULTI_PROCESS);
454-
}
453+
// mPreferences = context.getSharedPreferences(getDefaultSharedPreferencesName(context), Context.MODE_MULTI_PROCESS);
454+
} */
455455

456-
private static String getDefaultSharedPreferencesName(final Context context) {
456+
/* private static String getDefaultSharedPreferencesName(final Context context) {
457457
return SDK_INT >= N ? PreferenceManager.getDefaultSharedPreferencesName(context) : context.getPackageName() + "_preferences";
458-
}
458+
} */
459459

460460

461461

462462
private final ConversationManager mConversationManager = new ConversationManager();
463463
private MessagingBuilder mMessagingBuilder;
464464
private boolean mWeChatTargetingO;
465-
private SharedPreferences mPreferences;
466-
private String mPrefKeyWear;
465+
// private SharedPreferences mPreferences;
466+
// private String mPrefKeyWear;
467467
// private final Handler mHandler = new Handler();
468468

469469
static final String TAG = "Nevo.Decorator[WeChat]";

src/main/java/com/oasisfeng/nevo/sdk/NevoDecoratorService.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,21 @@ protected static boolean hasArchivedNotifications(String key) {
177177
return map.containsKey(key);
178178
}
179179

180-
@Keep public void onCreate(SharedPreferences pref) {}
180+
protected final String prefKey;
181+
private boolean disabled;
182+
183+
public NevoDecoratorService() {
184+
this.prefKey = getClass().getSimpleName();
185+
}
186+
187+
public boolean isDisabled() { return disabled; }
188+
public void setDisabled(boolean disabled) { this.disabled = disabled; }
189+
190+
@Keep public void onCreate(SharedPreferences pref) {
191+
this.disabled = !pref.getBoolean(prefKey + ".enabled", true);
192+
if (BuildConfig.DEBUG) Log.d(TAG, prefKey + ".disabled " + this.disabled);
193+
}
194+
181195
@Keep public void onDestroy() {}
182196

183197

src/main/java/com/oasisfeng/nevo/xposed/MainHook.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
import androidx.annotation.Keep;
1313

14+
import java.io.File;
1415
import java.lang.reflect.Field;
1516
import java.lang.reflect.Method;
1617
import java.util.ArrayList;
1718
import java.util.List;
19+
import java.util.Map;
1820
import java.util.concurrent.atomic.AtomicReference;
1921
import java.util.function.Consumer;
2022

23+
import com.notxx.xposed.DeviceSharedPreferences;
24+
2125
import com.oasisfeng.nevo.sdk.HookSupport;
2226
import com.oasisfeng.nevo.sdk.NevoDecoratorService;
2327
import com.oasisfeng.nevo.xposed.BuildConfig;
@@ -37,7 +41,7 @@
3741
public class MainHook implements IXposedHookLoadPackage {
3842
private static final String TAG = "MainHook";
3943

40-
private final XSharedPreferences pref = new XSharedPreferences(BuildConfig.APPLICATION_ID);
44+
private final XSharedPreferences pref = DeviceSharedPreferences.get(BuildConfig.APPLICATION_ID);
4145
private final NevoDecoratorService wechat = new com.oasisfeng.nevo.decorators.wechat.WeChatDecorator();
4246
private final NevoDecoratorService miui = new com.oasisfeng.nevo.decorators.MIUIDecorator();
4347
private final NevoDecoratorService media = new com.oasisfeng.nevo.decorators.media.MediaDecorator();
@@ -202,11 +206,13 @@ protected void beforeHookedMethod(MethodHookParam param) {
202206
}
203207
});
204208
} catch (XposedHelpers.ClassNotFoundError e) { XposedBridge.log("NotificationManager hook failed"); }
205-
if (pref.getBoolean("decorator_wechat.enabled", false) && (wechat instanceof HookSupport)) ((HookSupport)wechat).hook(loadPackageParam); // TODO
209+
wechat.onCreate(pref);
210+
if (!wechat.isDisabled() && (wechat instanceof HookSupport)) ((HookSupport)wechat).hook(loadPackageParam); // TODO
206211
}
207212

208213
private void onCreate(Context context) {
209214
NevoDecoratorService.setAppContext(context);
215+
210216
wechat.onCreate(pref);
211217
miui.onCreate(pref);
212218
media.onCreate(pref);
@@ -219,7 +225,7 @@ private void preApply(NotificationManager nm, String tag, int id, Notification n
219225
return;
220226
}
221227
XposedHelpers.setAdditionalInstanceField(n, "pre-applied", true);
222-
if (pref.getBoolean("decorator_wechat.enabled", false)) wechat.preApply(nm, tag, id, n);
228+
if (!wechat.isDisabled()) wechat.preApply(nm, tag, id, n);
223229
}
224230

225231
private void onNotificationPosted(StatusBarNotification sbn) {
@@ -230,24 +236,24 @@ private void onNotificationPosted(StatusBarNotification sbn) {
230236
XposedHelpers.setAdditionalInstanceField(sbn, "applied", true);
231237
switch (sbn.getPackageName()) {
232238
case "com.tencent.mm":
233-
if (pref.getBoolean("decorator_wechat.enabled", false)) wechat.apply(sbn);
239+
if (!wechat.isDisabled()) wechat.apply(sbn);
234240
break;
235241
case "com.xiaomi.xmsf":
236-
if (pref.getBoolean("decorator_miui.enabled", false)) miui.apply(sbn);
242+
if (!miui.isDisabled()) miui.apply(sbn);
237243
break;
238244
}
239-
if (pref.getBoolean("decorator_media.enabled", false)) media.apply(sbn);
245+
if (!media.isDisabled()) media.apply(sbn);
240246
}
241247

242248
private void onNotificationRemoved(StatusBarNotification sbn, int reason) {
243249
switch (sbn.getPackageName()) {
244250
case "com.tencent.mm":
245-
if (pref.getBoolean("decorator_wechat.enabled", false)) wechat.onNotificationRemoved(sbn, reason);
251+
if (!wechat.isDisabled()) wechat.onNotificationRemoved(sbn, reason);
246252
break;
247253
case "com.xiaomi.xmsf":
248-
if (pref.getBoolean("decorator_miui.enabled", false)) miui.onNotificationRemoved(sbn, reason);
254+
if (!miui.isDisabled()) miui.onNotificationRemoved(sbn, reason);
249255
break;
250256
}
251-
if (pref.getBoolean("decorator_media.enabled", false)) media.onNotificationRemoved(sbn, reason);
257+
if (!media.isDisabled()) media.onNotificationRemoved(sbn, reason);
252258
}
253259
}

src/main/java/com/oasisfeng/nevo/xposed/MainPreference.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ public class MainPreference extends PreferenceFragment {
1515
public void onCreate(Bundle savedInstanceState) {
1616
super.onCreate(savedInstanceState);
1717
PreferenceManager manager = getPreferenceManager();
18-
// if (SDK_INT >= N) manager.setStorageDeviceProtected();
19-
Map<String, ?> map = manager.getSharedPreferences().getAll();
20-
for (Map.Entry<String, ?> entry : map.entrySet()) {
21-
Log.d("inspect", entry.getKey() + "=>" + entry.getValue());
22-
}
18+
if (SDK_INT >= N) manager.setStorageDeviceProtected();
2319
addPreferencesFromResource(R.xml.main_preference);
2420
}
2521
}

src/main/res/xml/main_preference.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,34 @@
33

44
<!-- wechat -->
55
<PreferenceCategory
6-
android:key="decorator_wechat"
6+
android:key="WeChatDecorator"
77
android:title="@string/decorator_wechat_title">
88
<CheckBoxPreference
9-
android:key="decorator_wechat.enabled"
9+
android:key="WeChatDecorator.enabled"
1010
android:summary="@string/decorator_wechat_description"
1111
android:title="@string/decorator_enabled"/>
1212
<CheckBoxPreference
13-
android:key="decorator_wechat.miui_fix"
13+
android:key="WeChatDecorator.miui_fix"
1414
android:summary="@string/decorator_wechat_miui_fix"
1515
android:title="@string/decorator_fix_enabled"/>
1616
</PreferenceCategory>
1717

1818
<!-- miui -->
1919
<PreferenceCategory
20-
android:key="decorator_miui"
20+
android:key="MIUIDecorator"
2121
android:title="@string/decorator_miui_title">
2222
<CheckBoxPreference
23-
android:key="decorator_miui.enabled"
23+
android:key="MIUIDecorator.enabled"
2424
android:summary="@string/decorator_miui_description"
2525
android:title="@string/decorator_enabled"/>
2626
</PreferenceCategory>
2727

2828
<!-- media -->
2929
<PreferenceCategory
30-
android:key="decorator_media"
30+
android:key="MediaDecorator"
3131
android:title="@string/decorator_media_title">
3232
<CheckBoxPreference
33-
android:key="decorator_media.enabled"
33+
android:key="MediaDecorator.enabled"
3434
android:summary="@string/decorator_media_description"
3535
android:title="@string/decorator_enabled"/>
3636
</PreferenceCategory>

0 commit comments

Comments
 (0)