Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e4a8dbd8 authored by Todd Kennedy's avatar Todd Kennedy
Browse files

setup content observer statically

Instead of waiting for the first time we get the app op default mode,
just register the content observer for the sms & call log restriction.
This is temporary code anyway and will be removed according to a
STOPSHIP comment. So, the minor hit taken during system start is okay
for now.

Test: Device boots.
Change-Id: I55cc57ddfe80acf304b5126db16f5813a97c7042
Fixes: 119080532
parent 755cc665
Loading
Loading
Loading
Loading
+16 −21
Original line number Diff line number Diff line
@@ -1625,9 +1625,6 @@ public class AppOpsManager {
            case AppOpsManager.OP_READ_CALL_LOG:
            case AppOpsManager.OP_WRITE_CALL_LOG:
            case AppOpsManager.OP_PROCESS_OUTGOING_CALLS: {
                if (sSmsAndCallLogRestrictionEnabled.get() < 0) {
                    startWatchingSmsRestrictionEnabled();
                }
                if (sSmsAndCallLogRestrictionEnabled.get() == 1) {
                    return AppOpsManager.MODE_DEFAULT;
                }
@@ -1640,17 +1637,14 @@ public class AppOpsManager {
    private static final AtomicInteger sSmsAndCallLogRestrictionEnabled = new AtomicInteger(-1);

    // STOPSHIP b/118520006: Hardcode the default values once the feature is stable.
    private static void startWatchingSmsRestrictionEnabled() {
    static {
        final Context context = ActivityThread.currentApplication();
        if (context == null) {
            // Should never happen
            return;
        }

        if (context != null) {
            sSmsAndCallLogRestrictionEnabled.set(ActivityThread.currentActivityThread()
                        .getIntCoreSetting(Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, 0));

        final Uri uri = Settings.Global.getUriFor(Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED);
            final Uri uri =
                    Settings.Global.getUriFor(Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED);
            context.getContentResolver().registerContentObserver(uri, false, new ContentObserver(
                    context.getMainThreadHandler()) {
                @Override
@@ -1661,6 +1655,7 @@ public class AppOpsManager {
                }
            });
        }
    }

    /**
     * Retrieve the default mode for the app op.