diff options
| author | 2020-08-27 13:45:15 +0000 | |
|---|---|---|
| committer | 2020-08-27 13:45:15 +0000 | |
| commit | 0f292589f9adc9e7a8ce959da4aba9feab9a6ad2 (patch) | |
| tree | 64211e0d997befbed406abdaf5977dd10b11b134 | |
| parent | 604af18a391148082d5f90c55f3ce1f1a2e78f79 (diff) | |
| parent | 8525fa39d84ad3a140bd4be50f7d6d5d9edf8ba6 (diff) | |
Merge "Remove Dependency.get from CarDevProvCont."
3 files changed, 116 insertions, 52 deletions
diff --git a/packages/CarSystemUI/src/com/android/systemui/car/CarDeviceProvisionedControllerImpl.java b/packages/CarSystemUI/src/com/android/systemui/car/CarDeviceProvisionedControllerImpl.java index a2ba880facfe..fef032414bb9 100644 --- a/packages/CarSystemUI/src/com/android/systemui/car/CarDeviceProvisionedControllerImpl.java +++ b/packages/CarSystemUI/src/com/android/systemui/car/CarDeviceProvisionedControllerImpl.java @@ -16,20 +16,19 @@ package com.android.systemui.car; +import android.annotation.NonNull; import android.app.ActivityManager; import android.car.settings.CarSettings; -import android.content.ContentResolver; -import android.content.Context; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; -import android.provider.Settings; -import com.android.systemui.Dependency; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.statusbar.policy.DeviceProvisionedControllerImpl; +import com.android.systemui.util.settings.GlobalSettings; +import com.android.systemui.util.settings.SecureSettings; import javax.inject.Inject; @@ -40,30 +39,33 @@ import javax.inject.Inject; @SysUISingleton public class CarDeviceProvisionedControllerImpl extends DeviceProvisionedControllerImpl implements CarDeviceProvisionedController { - private static final Uri USER_SETUP_IN_PROGRESS_URI = Settings.Secure.getUriFor( - CarSettings.Secure.KEY_SETUP_WIZARD_IN_PROGRESS); - private final ContentObserver mCarSettingsObserver = new ContentObserver( - Dependency.get(Dependency.MAIN_HANDLER)) { - - @Override - public void onChange(boolean selfChange, Uri uri, int flags) { - if (USER_SETUP_IN_PROGRESS_URI.equals(uri)) { - notifyUserSetupInProgressChanged(); - } - } - }; - private final ContentResolver mContentResolver; + private final Uri mUserSetupInProgressUri; + private final ContentObserver mCarSettingsObserver; + private final Handler mMainHandler; + private final SecureSettings mSecureSettings; @Inject - public CarDeviceProvisionedControllerImpl(Context context, @Main Handler mainHandler, - BroadcastDispatcher broadcastDispatcher) { - super(context, mainHandler, broadcastDispatcher); - mContentResolver = context.getContentResolver(); + public CarDeviceProvisionedControllerImpl(@Main Handler mainHandler, + BroadcastDispatcher broadcastDispatcher, GlobalSettings globalSetting, + SecureSettings secureSettings) { + super(mainHandler, broadcastDispatcher, globalSetting, secureSettings); + mMainHandler = mainHandler; + mSecureSettings = secureSettings; + mUserSetupInProgressUri = mSecureSettings.getUriFor( + CarSettings.Secure.KEY_SETUP_WIZARD_IN_PROGRESS); + mCarSettingsObserver = new ContentObserver(mMainHandler) { + @Override + public void onChange(boolean selfChange, Uri uri, int flags) { + if (mUserSetupInProgressUri.equals(uri)) { + notifyUserSetupInProgressChanged(); + } + } + }; } @Override public boolean isUserSetupInProgress(int user) { - return Settings.Secure.getIntForUser(mContentResolver, + return mSecureSettings.getIntForUser( CarSettings.Secure.KEY_SETUP_WIZARD_IN_PROGRESS, /* def= */ 0, user) != 0; } @@ -73,7 +75,7 @@ public class CarDeviceProvisionedControllerImpl extends DeviceProvisionedControl } @Override - public void addCallback(DeviceProvisionedListener listener) { + public void addCallback(@NonNull DeviceProvisionedListener listener) { super.addCallback(listener); if (listener instanceof CarDeviceProvisionedListener) { ((CarDeviceProvisionedListener) listener).onUserSetupInProgressChanged(); @@ -82,9 +84,9 @@ public class CarDeviceProvisionedControllerImpl extends DeviceProvisionedControl @Override protected void startListening(int user) { - mContentResolver.registerContentObserver( - USER_SETUP_IN_PROGRESS_URI, /* notifyForDescendants= */ true, mCarSettingsObserver, - user); + mSecureSettings.registerContentObserverForUser( + mUserSetupInProgressUri, /* notifyForDescendants= */ true, + mCarSettingsObserver, user); // The SUW Flag observer is registered before super.startListening() so that the observer is // in place before DeviceProvisionedController starts to track user switches which avoids // an edge case where our observer gets registered twice. @@ -94,16 +96,16 @@ public class CarDeviceProvisionedControllerImpl extends DeviceProvisionedControl @Override protected void stopListening() { super.stopListening(); - mContentResolver.unregisterContentObserver(mCarSettingsObserver); + mSecureSettings.unregisterContentObserver(mCarSettingsObserver); } @Override public void onUserSwitched(int newUserId) { super.onUserSwitched(newUserId); - mContentResolver.unregisterContentObserver(mCarSettingsObserver); - mContentResolver.registerContentObserver( - USER_SETUP_IN_PROGRESS_URI, /* notifyForDescendants= */ true, mCarSettingsObserver, - newUserId); + mSecureSettings.unregisterContentObserver(mCarSettingsObserver); + mSecureSettings.registerContentObserverForUser( + mUserSetupInProgressUri, /* notifyForDescendants= */ true, + mCarSettingsObserver, newUserId); } private void notifyUserSetupInProgressChanged() { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceProvisionedControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceProvisionedControllerImpl.java index 9b4e16525df2..485b1b109eb4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceProvisionedControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceProvisionedControllerImpl.java @@ -15,8 +15,6 @@ package com.android.systemui.statusbar.policy; import android.app.ActivityManager; -import android.content.ContentResolver; -import android.content.Context; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; @@ -30,6 +28,8 @@ import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.settings.CurrentUserTracker; +import com.android.systemui.util.settings.GlobalSettings; +import com.android.systemui.util.settings.SecureSettings; import java.util.ArrayList; @@ -43,8 +43,8 @@ public class DeviceProvisionedControllerImpl extends CurrentUserTracker implemen protected static final String TAG = DeviceProvisionedControllerImpl.class.getSimpleName(); protected final ArrayList<DeviceProvisionedListener> mListeners = new ArrayList<>(); - private final ContentResolver mContentResolver; - private final Context mContext; + private final GlobalSettings mGlobalSettings; + private final SecureSettings mSecureSettings; private final Uri mDeviceProvisionedUri; private final Uri mUserSetupUri; protected final ContentObserver mSettingsObserver; @@ -52,13 +52,14 @@ public class DeviceProvisionedControllerImpl extends CurrentUserTracker implemen /** */ @Inject - public DeviceProvisionedControllerImpl(Context context, @Main Handler mainHandler, - BroadcastDispatcher broadcastDispatcher) { + public DeviceProvisionedControllerImpl(@Main Handler mainHandler, + BroadcastDispatcher broadcastDispatcher, GlobalSettings globalSettings, + SecureSettings secureSettings) { super(broadcastDispatcher); - mContext = context; - mContentResolver = context.getContentResolver(); - mDeviceProvisionedUri = Global.getUriFor(Global.DEVICE_PROVISIONED); - mUserSetupUri = Secure.getUriFor(Secure.USER_SETUP_COMPLETE); + mGlobalSettings = globalSettings; + mSecureSettings = secureSettings; + mDeviceProvisionedUri = mGlobalSettings.getUriFor(Global.DEVICE_PROVISIONED); + mUserSetupUri = mSecureSettings.getUriFor(Secure.USER_SETUP_COMPLETE); mSettingsObserver = new ContentObserver(mainHandler) { @Override public void onChange(boolean selfChange, Uri uri, int flags) { @@ -74,13 +75,12 @@ public class DeviceProvisionedControllerImpl extends CurrentUserTracker implemen @Override public boolean isDeviceProvisioned() { - return Global.getInt(mContentResolver, Global.DEVICE_PROVISIONED, 0) != 0; + return mGlobalSettings.getInt(Global.DEVICE_PROVISIONED, 0) != 0; } @Override public boolean isUserSetup(int currentUser) { - return Secure.getIntForUser(mContentResolver, Secure.USER_SETUP_COMPLETE, 0, currentUser) - != 0; + return mSecureSettings.getIntForUser(Secure.USER_SETUP_COMPLETE, 0, currentUser) != 0; } @Override @@ -107,24 +107,24 @@ public class DeviceProvisionedControllerImpl extends CurrentUserTracker implemen } protected void startListening(int user) { - mContentResolver.registerContentObserver(mDeviceProvisionedUri, true, + mGlobalSettings.registerContentObserverForUser(mDeviceProvisionedUri, true, mSettingsObserver, 0); - mContentResolver.registerContentObserver(mUserSetupUri, true, + mSecureSettings.registerContentObserverForUser(mUserSetupUri, true, mSettingsObserver, user); startTracking(); } protected void stopListening() { stopTracking(); - mContentResolver.unregisterContentObserver(mSettingsObserver); + mGlobalSettings.unregisterContentObserver(mSettingsObserver); } @Override public void onUserSwitched(int newUserId) { - mContentResolver.unregisterContentObserver(mSettingsObserver); - mContentResolver.registerContentObserver(mDeviceProvisionedUri, true, + mGlobalSettings.unregisterContentObserver(mSettingsObserver); + mGlobalSettings.registerContentObserverForUser(mDeviceProvisionedUri, true, mSettingsObserver, 0); - mContentResolver.registerContentObserver(mUserSetupUri, true, + mSecureSettings.registerContentObserverForUser(mUserSetupUri, true, mSettingsObserver, newUserId); notifyUserChanged(); } diff --git a/packages/SystemUI/src/com/android/systemui/util/settings/SettingsProxy.java b/packages/SystemUI/src/com/android/systemui/util/settings/SettingsProxy.java index 5c37f797b678..5aaf7f680d5c 100644 --- a/packages/SystemUI/src/com/android/systemui/util/settings/SettingsProxy.java +++ b/packages/SystemUI/src/com/android/systemui/util/settings/SettingsProxy.java @@ -67,7 +67,35 @@ public interface SettingsProxy { * Implicitly calls {@link #getUriFor(String)} on the passed in name. */ default void registerContentObserver(String name, ContentObserver settingsObserver) { - registerContentObserverForUser(name, settingsObserver, getUserId()); + registerContentObserver(getUriFor(name), settingsObserver); + } + + /** + * Convenience wrapper around + * {@link ContentResolver#registerContentObserver(Uri, boolean, ContentObserver)}.' + */ + default void registerContentObserver(Uri uri, ContentObserver settingsObserver) { + registerContentObserverForUser(uri, settingsObserver, getUserId()); + } + + /** + * Convenience wrapper around + * {@link ContentResolver#registerContentObserver(Uri, boolean, ContentObserver)}.' + * + * Implicitly calls {@link #getUriFor(String)} on the passed in name. + */ + default void registerContentObserver(String name, boolean notifyForDescendents, + ContentObserver settingsObserver) { + registerContentObserver(getUriFor(name), notifyForDescendents, settingsObserver); + } + + /** + * Convenience wrapper around + * {@link ContentResolver#registerContentObserver(Uri, boolean, ContentObserver)}.' + */ + default void registerContentObserver(Uri uri, boolean notifyForDescendents, + ContentObserver settingsObserver) { + registerContentObserverForUser(uri, notifyForDescendents, settingsObserver, getUserId()); } /** @@ -78,8 +106,42 @@ public interface SettingsProxy { */ default void registerContentObserverForUser( String name, ContentObserver settingsObserver, int userHandle) { + registerContentObserverForUser( + getUriFor(name), settingsObserver, userHandle); + } + + /** + * Convenience wrapper around + * {@link ContentResolver#registerContentObserver(Uri, boolean, ContentObserver, int)} + */ + default void registerContentObserverForUser( + Uri uri, ContentObserver settingsObserver, int userHandle) { + registerContentObserverForUser( + uri, false, settingsObserver, userHandle); + } + + /** + * Convenience wrapper around + * {@link ContentResolver#registerContentObserver(Uri, boolean, ContentObserver, int)} + * + * Implicitly calls {@link #getUriFor(String)} on the passed in name. + */ + default void registerContentObserverForUser( + String name, boolean notifyForDescendents, ContentObserver settingsObserver, + int userHandle) { + registerContentObserverForUser( + getUriFor(name), notifyForDescendents, settingsObserver, userHandle); + } + + /** + * Convenience wrapper around + * {@link ContentResolver#registerContentObserver(Uri, boolean, ContentObserver, int)} + */ + default void registerContentObserverForUser( + Uri uri, boolean notifyForDescendents, ContentObserver settingsObserver, + int userHandle) { getContentResolver().registerContentObserver( - getUriFor(name), false, settingsObserver, userHandle); + uri, notifyForDescendents, settingsObserver, userHandle); } /** See {@link ContentResolver#unregisterContentObserver(ContentObserver)}. */ |