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

Commit 7ad6b841 authored by Meng Wang's avatar Meng Wang Committed by Android (Google) Code Review
Browse files

Merge "Replace IDeviceIdleController with PowerWhitelistManager"

parents 48b86e8f 2543b88a
Loading
Loading
Loading
Loading
+16 −22
Original line number Diff line number Diff line
@@ -48,9 +48,9 @@ import android.os.AsyncResult;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.IDeviceIdleController;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerWhitelistManager;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
@@ -239,8 +239,7 @@ public abstract class InboundSmsHandler extends StateMachine {

    private LocalLog mLocalLog = new LocalLog(64);

    @UnsupportedAppUsage
    IDeviceIdleController mDeviceIdleController;
    PowerWhitelistManager mPowerWhitelistManager;

    protected static boolean sEnableCbModule = false;

@@ -287,8 +286,8 @@ public abstract class InboundSmsHandler extends StateMachine {
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name);
        mWakeLock.acquire();    // wake lock released after we enter idle state
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        mDeviceIdleController = TelephonyComponentFactory.getInstance()
                .inject(IDeviceIdleController.class.getName()).getIDeviceIdleController();
        mPowerWhitelistManager =
                (PowerWhitelistManager) mContext.getSystemService(Context.POWER_WHITELIST_MANAGER);
        mCellBroadcastServiceManager = new CellBroadcastServiceManager(context, phone);

        addState(mDefaultState);
@@ -1248,14 +1247,11 @@ public abstract class InboundSmsHandler extends StateMachine {
            bopts.setBackgroundActivityStartsAllowed(true);
            bundle = bopts.toBundle();
        }
        try {
            long duration = mDeviceIdleController.addPowerSaveTempWhitelistAppForSms(
                    pkgName, 0, reason);
        long duration = mPowerWhitelistManager.whitelistAppTemporarilyForEvent(
                pkgName, PowerWhitelistManager.EVENT_SMS, reason);
        if (bopts == null) bopts = BroadcastOptions.makeBasic();
        bopts.setTemporaryAppWhitelistDuration(duration);
        bundle = bopts.toBundle();
        } catch (RemoteException e) {
        }

        return bundle;
    }
@@ -1507,15 +1503,13 @@ public abstract class InboundSmsHandler extends StateMachine {
                intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
                // Only the primary user will receive notification of incoming mms.
                // That app will do the actual downloading of the mms.
                Bundle options = null;
                try {
                    long duration = mDeviceIdleController.addPowerSaveTempWhitelistAppForMms(
                            mContext.getPackageName(), 0, "mms-broadcast");
                long duration = mPowerWhitelistManager.whitelistAppTemporarilyForEvent(
                        mContext.getPackageName(),
                        PowerWhitelistManager.EVENT_MMS,
                        "mms-broadcast");
                BroadcastOptions bopts = BroadcastOptions.makeBasic();
                bopts.setTemporaryAppWhitelistDuration(duration);
                    options = bopts.toBundle();
                } catch (RemoteException e) {
                }
                Bundle options = bopts.toBundle();

                String mimeType = intent.getType();
                dispatchIntent(intent, WapPushOverSms.getPermissionForType(mimeType),
+0 −7
Original line number Diff line number Diff line
@@ -22,9 +22,7 @@ import android.content.Context;
import android.content.res.XmlResourceParser;
import android.database.Cursor;
import android.os.Handler;
import android.os.IDeviceIdleController;
import android.os.Looper;
import android.os.ServiceManager;
import android.system.ErrnoException;
import android.system.Os;
import android.system.OsConstants;
@@ -409,11 +407,6 @@ public class TelephonyComponentFactory {
        return CdmaSubscriptionSourceManager.getInstance(context, ci, h, what, obj);
    }

    public IDeviceIdleController getIDeviceIdleController() {
        return IDeviceIdleController.Stub.asInterface(
                ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
    }

    public LocaleTracker makeLocaleTracker(Phone phone, NitzStateMachine nitzStateMachine,
                                           Looper looper) {
        return new LocaleTracker(phone, nitzStateMachine, looper);
+11 −15
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.os.IDeviceIdleController;
import android.os.PowerWhitelistManager;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
@@ -73,8 +73,7 @@ public class WapPushOverSms implements ServiceConnection {

    @UnsupportedAppUsage
    private final Context mContext;
    @UnsupportedAppUsage
    private IDeviceIdleController mDeviceIdleController;
    PowerWhitelistManager mPowerWhitelistManager;

    private String mWapPushManagerPackage;

@@ -136,8 +135,8 @@ public class WapPushOverSms implements ServiceConnection {

    public WapPushOverSms(Context context) {
        mContext = context;
        mDeviceIdleController = TelephonyComponentFactory.getInstance()
                .inject(IDeviceIdleController.class.getName()).getIDeviceIdleController();
        mPowerWhitelistManager =
                (PowerWhitelistManager) mContext.getSystemService(Context.POWER_WHITELIST_MANAGER);

        UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);

@@ -351,8 +350,8 @@ public class WapPushOverSms implements ServiceConnection {
                    if (DBG) Rlog.w(TAG, "wap push manager not found!");
                } else {
                    synchronized (this) {
                        mDeviceIdleController.addPowerSaveTempWhitelistAppForMms(
                                mWapPushManagerPackage, 0, "mms-mgr");
                        mPowerWhitelistManager.whitelistAppTemporarilyForEvent(
                                mWapPushManagerPackage, PowerWhitelistManager.EVENT_MMS, "mms-mgr");
                    }

                    Intent intent = new Intent();
@@ -409,14 +408,11 @@ public class WapPushOverSms implements ServiceConnection {
            intent.setComponent(componentName);
            if (DBG) Rlog.v(TAG, "Delivering MMS to: " + componentName.getPackageName() +
                    " " + componentName.getClassName());
            try {
                long duration = mDeviceIdleController.addPowerSaveTempWhitelistAppForMms(
                        componentName.getPackageName(), 0, "mms-app");
            long duration = mPowerWhitelistManager.whitelistAppTemporarilyForEvent(
                    componentName.getPackageName(), PowerWhitelistManager.EVENT_MMS, "mms-app");
            BroadcastOptions bopts = BroadcastOptions.makeBasic();
            bopts.setTemporaryAppWhitelistDuration(duration);
            options = bopts.toBundle();
            } catch (RemoteException e) {
            }
        }

        handler.dispatchIntent(intent, getPermissionForType(result.mimeType),
+4 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.IInterface;
import android.os.PersistableBundle;
import android.os.PowerWhitelistManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.preference.PreferenceManager;
@@ -258,6 +259,8 @@ public class ContextFixture implements TestFixture<Context> {
                    // PowerManager and DisplayManager are final classes so cannot be mocked,
                    // return real services.
                    return TestApplication.getAppContext().getSystemService(name);
                case Context.POWER_WHITELIST_MANAGER:
                    return mPowerWhitelistManager;
                default:
                    return null;
            }
@@ -599,6 +602,7 @@ public class ContextFixture implements TestFixture<Context> {
    private final TelephonyRegistryManager mTelephonyRegistryManager =
        mock(TelephonyRegistryManager.class);
    private final BatteryStatsManager mBatteryStatsManager = mock(BatteryStatsManager.class);
    private final PowerWhitelistManager mPowerWhitelistManager = mock(PowerWhitelistManager.class);

    private final ContentProvider mContentProvider = spy(new FakeContentProvider());

+0 −5
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.IDeviceIdleController;
import android.os.Looper;
import android.os.Message;
import android.os.MessageQueue;
@@ -189,8 +188,6 @@ public abstract class TelephonyTest {
    @Mock
    protected SimulatedCommandsVerifier mSimulatedCommandsVerifier;
    @Mock
    protected IDeviceIdleController mIDeviceIdleController;
    @Mock
    protected InboundSmsHandler mInboundSmsHandler;
    @Mock
    protected WspTypeDecoder mWspTypeDecoder;
@@ -436,8 +433,6 @@ public abstract class TelephonyTest {
                .getCdmaSubscriptionSourceManagerInstance(nullable(Context.class),
                        nullable(CommandsInterface.class), nullable(Handler.class),
                        anyInt(), nullable(Object.class));
        doReturn(mIDeviceIdleController).when(mTelephonyComponentFactory)
                .getIDeviceIdleController();
        doReturn(mImsExternalCallTracker).when(mTelephonyComponentFactory)
                .makeImsExternalCallTracker(nullable(ImsPhone.class));
        doReturn(mAppSmsManager).when(mTelephonyComponentFactory)