Remove Dependency.get from CarDevProvCont.
Remove a call to Dependency.get(MAIN_HANDLER) from the CarDeviceProvisionedControllerImpl. Use the new GlobalSettings and SecureSettings classes while we're here, removing the need to inject a context. NO_TYPO_CHECK=Spelling errors inherited from framework class. Bug: 144503618 Test: manual Change-Id: Idf14549abe3d80b62a4be7ef7f162f1224b35c4a
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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)}. */
|
||||
|
||||
Reference in New Issue
Block a user