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

Commit 73ea0ae1 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Fix bugs around manager fetching.

A recent patch started returning "null" when a Binder service
required to provide a manager wasn't yet registered.

This fixes four locations where that new logging was triggered: in
two cases by adjusting the fetching ordering, and in two other cases
by only fetching when the device supports the manager.

Bug: 28634953
Change-Id: I84dbccffa4ac760c10a2bbcb234f21272bfecb91
parent 49ca529a
Loading
Loading
Loading
Loading
+3 −15
Original line number Diff line number Diff line
@@ -141,9 +141,6 @@ import java.util.HashMap;
final class SystemServiceRegistry {
    private static final String TAG = "SystemServiceRegistry";

    // When set, include stack traces when services aren't published
    private static final boolean DEBUG_EARLY_CALLERS = true;

    // Service registry information.
    // This information is never changed once static initialization has completed.
    private static final HashMap<Class<?>, String> SYSTEM_SERVICE_NAMES =
@@ -385,9 +382,6 @@ final class SystemServiceRegistry {
            public PowerManager createService(ContextImpl ctx) throws ServiceNotFoundException {
                IBinder b = ServiceManager.getServiceOrThrow(Context.POWER_SERVICE);
                IPowerManager service = IPowerManager.Stub.asInterface(b);
                if (service == null) {
                    Log.wtf(TAG, "Failed to get power manager service.");
                }
                return new PowerManager(ctx.getOuterContext(),
                        service, ctx.mMainThread.getHandler());
            }});
@@ -398,9 +392,6 @@ final class SystemServiceRegistry {
            public RecoverySystem createService(ContextImpl ctx) throws ServiceNotFoundException {
                IBinder b = ServiceManager.getServiceOrThrow(Context.RECOVERY_SERVICE);
                IRecoverySystem service = IRecoverySystem.Stub.asInterface(b);
                if (service == null) {
                    Log.wtf(TAG, "Failed to get recovery service.");
                }
                return new RecoverySystem(service);
            }});

@@ -525,9 +516,6 @@ final class SystemServiceRegistry {
            public WifiNanManager createService() throws ServiceNotFoundException {
                IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_NAN_SERVICE);
                IWifiNanManager service = IWifiNanManager.Stub.asInterface(b);
                if (service == null) {
                    return null;
                }
                return new WifiNanManager(service);
            }});

@@ -840,7 +828,7 @@ final class SystemServiceRegistry {
                        service = createService(ctx);
                        cache[mCacheIndex] = service;
                    } catch (ServiceNotFoundException e) {
                        Log.w(TAG, e.getMessage(), DEBUG_EARLY_CALLERS ? e : null);
                        Log.wtf(TAG, e.getMessage(), e);
                    }
                }
                return (T)service;
@@ -864,7 +852,7 @@ final class SystemServiceRegistry {
                    try {
                        mCachedInstance = createService();
                    } catch (ServiceNotFoundException e) {
                        Log.w(TAG, e.getMessage(), DEBUG_EARLY_CALLERS ? e : null);
                        Log.wtf(TAG, e.getMessage(), e);
                    }
                }
                return mCachedInstance;
@@ -897,7 +885,7 @@ final class SystemServiceRegistry {
                    try {
                        mCachedInstance = createService(appContext != null ? appContext : ctx);
                    } catch (ServiceNotFoundException e) {
                        Log.w(TAG, e.getMessage(), DEBUG_EARLY_CALLERS ? e : null);
                        Log.wtf(TAG, e.getMessage(), e);
                    }
                }
                return mCachedInstance;
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ public class AppWidgetService extends SystemService {

    @Override
    public void onStart() {
        mImpl.onStart();
        publishBinderService(Context.APPWIDGET_SERVICE, mImpl);
        AppWidgetBackupBridge.register(mImpl);
    }
+15 −12
Original line number Diff line number Diff line
@@ -201,21 +201,21 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku

    private final SparseArray<ArraySet<String>> mWidgetPackages = new SparseArray<>();

    private final BackupRestoreController mBackupRestoreController;
    private BackupRestoreController mBackupRestoreController;

    private final Context mContext;

    private final IPackageManager mPackageManager;
    private final AlarmManager mAlarmManager;
    private final UserManager mUserManager;
    private final AppOpsManager mAppOpsManager;
    private final KeyguardManager mKeyguardManager;
    private final DevicePolicyManagerInternal mDevicePolicyManagerInternal;
    private IPackageManager mPackageManager;
    private AlarmManager mAlarmManager;
    private UserManager mUserManager;
    private AppOpsManager mAppOpsManager;
    private KeyguardManager mKeyguardManager;
    private DevicePolicyManagerInternal mDevicePolicyManagerInternal;

    private final SecurityPolicy mSecurityPolicy;
    private SecurityPolicy mSecurityPolicy;

    private final Handler mSaveStateHandler;
    private final Handler mCallbackHandler;
    private Handler mSaveStateHandler;
    private Handler mCallbackHandler;

    private Locale mLocale;

@@ -224,10 +224,13 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
    private boolean mSafeMode;
    private int mMaxWidgetBitmapMemory;

    private final IconUtilities mIconUtilities;
    private IconUtilities mIconUtilities;

    AppWidgetServiceImpl(Context context) {
        mContext = context;
    }

    public void onStart() {
        mPackageManager = AppGlobals.getPackageManager();
        mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
@@ -238,7 +241,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
        mCallbackHandler = new CallbackHandler(mContext.getMainLooper());
        mBackupRestoreController = new BackupRestoreController();
        mSecurityPolicy = new SecurityPolicy();
        mIconUtilities = new IconUtilities(context);
        mIconUtilities = new IconUtilities(mContext);

        computeMaximumWidgetBitmapMemory();
        registerBroadcastReceiver();
+2 −3
Original line number Diff line number Diff line
@@ -746,9 +746,8 @@ public class AudioService extends IAudioService.Stub {
                                    BluetoothProfile.A2DP);
        }

        mHdmiManager =
                (HdmiControlManager) mContext.getSystemService(Context.HDMI_CONTROL_SERVICE);
        if (mHdmiManager != null) {
        if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) {
            mHdmiManager = mContext.getSystemService(HdmiControlManager.class);
            synchronized (mHdmiManager) {
                mHdmiTvClient = mHdmiManager.getTvClient();
                if (mHdmiTvClient != null) {
+4 −4
Original line number Diff line number Diff line
@@ -1013,6 +1013,10 @@ public final class SystemServer {
            mSystemServiceManager.startService(SoundTriggerService.class);

            if (!disableNonCoreServices) {
                if (!disableTrustManager) {
                    mSystemServiceManager.startService(TrustManagerService.class);
                }

                if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) {
                    mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS);
                }
@@ -1142,10 +1146,6 @@ public final class SystemServer {
                }
                Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);

                if (!disableTrustManager) {
                    mSystemServiceManager.startService(TrustManagerService.class);
                }

                if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
                    mSystemServiceManager.startService(FingerprintService.class);
                }