Search in sources :

Example 36 with PowerManager

use of android.os.PowerManager in project android_frameworks_base by DirtyUnicorns.

the class FrameworkPerfActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set the layout for this activity.  You can find it
    // in res/layout/hello_activity.xml
    setContentView(R.layout.main);
    mFgSpinner = (Spinner) findViewById(R.id.fgspinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mAvailOpLabels);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mFgSpinner.setAdapter(adapter);
    mFgSpinner.setOnItemSelectedListener(this);
    mBgSpinner = (Spinner) findViewById(R.id.bgspinner);
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mAvailOpLabels);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mBgSpinner.setAdapter(adapter);
    mBgSpinner.setOnItemSelectedListener(this);
    mLimitSpinner = (Spinner) findViewById(R.id.limitspinner);
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mLimitLabels);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mLimitSpinner.setAdapter(adapter);
    mLimitSpinner.setOnItemSelectedListener(this);
    mTestTime = (TextView) findViewById(R.id.testtime);
    mLimitLabel = (TextView) findViewById(R.id.limitlabel);
    mStartButton = (Button) findViewById(R.id.start);
    mStartButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startRunning();
        }
    });
    mStopButton = (Button) findViewById(R.id.stop);
    mStopButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            stopRunning();
        }
    });
    mStopButton.setEnabled(false);
    mLocalCheckBox = (CheckBox) findViewById(R.id.local);
    mLog = (TextView) findViewById(R.id.log);
    mLog.setTextColor(Color.RED);
    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Scheduler");
    mPartialWakeLock.setReferenceCounted(false);
}
Also used : PowerManager(android.os.PowerManager) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 37 with PowerManager

use of android.os.PowerManager in project android_frameworks_base by DirtyUnicorns.

the class NetworkStatsServiceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    mServiceContext = new BroadcastInterceptingContext(getContext());
    mStatsDir = getContext().getFilesDir();
    if (mStatsDir.exists()) {
        IoUtils.deleteContents(mStatsDir);
    }
    mNetManager = createMock(INetworkManagementService.class);
    // TODO: Mock AlarmManager when migrating this test to Mockito.
    AlarmManager alarmManager = (AlarmManager) mServiceContext.getSystemService(Context.ALARM_SERVICE);
    mTime = createMock(TrustedTime.class);
    mSettings = createMock(NetworkStatsSettings.class);
    mConnManager = createMock(IConnectivityManager.class);
    PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    mService = new NetworkStatsService(mServiceContext, mNetManager, alarmManager, wakeLock, mTime, TelephonyManager.getDefault(), mSettings, new NetworkStatsObservers(), mStatsDir, getBaseDir(mStatsDir));
    mHandlerThread = new IdleableHandlerThread("HandlerThread");
    mHandlerThread.start();
    Handler.Callback callback = new NetworkStatsService.HandlerCallback(mService);
    mHandler = new Handler(mHandlerThread.getLooper(), callback);
    mService.setHandler(mHandler, callback);
    mService.bindConnectivityManager(mConnManager);
    mElapsedRealtime = 0L;
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectSystemReady();
    // catch INetworkManagementEventObserver during systemReady()
    final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
    mNetManager.registerObserver(capture(networkObserver));
    expectLastCall().atLeastOnce();
    replay();
    mService.systemReady();
    mSession = mService.openSession();
    verifyAndReset();
    mNetworkObserver = networkObserver.getValue();
}
Also used : TrustedTime(android.util.TrustedTime) INetworkManagementService(android.os.INetworkManagementService) BroadcastInterceptingContext(com.android.server.BroadcastInterceptingContext) Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler) Capture(org.easymock.Capture) NetworkStatsSettings(com.android.server.net.NetworkStatsService.NetworkStatsSettings) PowerManager(android.os.PowerManager) NetworkStatsService(com.android.server.net.NetworkStatsService) IAlarmManager(android.app.IAlarmManager) AlarmManager(android.app.AlarmManager) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) IConnectivityManager(android.net.IConnectivityManager)

Example 38 with PowerManager

use of android.os.PowerManager in project android_frameworks_base by DirtyUnicorns.

the class SoundTriggerTestActivity method screenWakeup.

private void screenWakeup() {
    if (mScreenWakelock == null) {
        PowerManager pm = ((PowerManager) getSystemService(POWER_SERVICE));
        mScreenWakelock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG);
    }
    mScreenWakelock.acquire();
}
Also used : PowerManager(android.os.PowerManager)

Example 39 with PowerManager

use of android.os.PowerManager in project android_frameworks_base by DirtyUnicorns.

the class RebootTile method handleLongClick.

@Override
protected void handleLongClick() {
    mHost.collapsePanels();
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        public void run() {
            PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
            pm.reboot(mRebootToRecovery ? "recovery" : "");
        }
    }, 500);
}
Also used : PowerManager(android.os.PowerManager) Handler(android.os.Handler)

Example 40 with PowerManager

use of android.os.PowerManager in project android_frameworks_base by DirtyUnicorns.

the class FingerprintManager method addLockoutResetCallback.

/**
     * @hide
     */
public void addLockoutResetCallback(final LockoutResetCallback callback) {
    if (mService != null) {
        try {
            final PowerManager powerManager = mContext.getSystemService(PowerManager.class);
            mService.addLockoutResetCallback(new IFingerprintServiceLockoutResetCallback.Stub() {

                @Override
                public void onLockoutReset(long deviceId) throws RemoteException {
                    final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lockoutResetCallback");
                    wakeLock.acquire();
                    mHandler.post(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                callback.onLockoutReset();
                            } finally {
                                wakeLock.release();
                            }
                        }
                    });
                }
            });
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    } else {
        Log.w(TAG, "addLockoutResetCallback(): Service not connected!");
    }
}
Also used : PowerManager(android.os.PowerManager) RemoteException(android.os.RemoteException)

Aggregations

PowerManager (android.os.PowerManager)598 Context (android.content.Context)112 Handler (android.os.Handler)112 Intent (android.content.Intent)93 IntentFilter (android.content.IntentFilter)72 PendingIntent (android.app.PendingIntent)46 RemoteException (android.os.RemoteException)37 IPowerManager (android.os.IPowerManager)33 SuppressLint (android.annotation.SuppressLint)30 View (android.view.View)27 IOException (java.io.IOException)27 ContentResolver (android.content.ContentResolver)26 HandlerThread (android.os.HandlerThread)26 SharedPreferences (android.content.SharedPreferences)23 KeyguardManager (android.app.KeyguardManager)18 ComponentName (android.content.ComponentName)18 Resources (android.content.res.Resources)18 TextView (android.widget.TextView)18 PackageManager (android.content.pm.PackageManager)17 Uri (android.net.Uri)16