Search in sources :

Example 86 with PowerManager

use of android.os.PowerManager in project AndroidChromium by JackyAndroid.

the class PrecacheController method acquirePrecachingWakeLock.

/** Acquires the precaching {@link WakeLock}. */
@VisibleForTesting
void acquirePrecachingWakeLock() {
    assert mNonThreadSafe.calledOnValidThread();
    Log.v(TAG, "acquiring wake lock");
    if (mPrecachingWakeLock == null) {
        PowerManager pm = (PowerManager) mAppContext.getSystemService(Context.POWER_SERVICE);
        mPrecachingWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    }
    mPrecachingWakeLock.acquire();
}
Also used : PowerManager(android.os.PowerManager) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 87 with PowerManager

use of android.os.PowerManager in project wifikeyboard by IvanVolosyuk.

the class WiFiInputMethod method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "wifikeyboard");
    //    Debug.d("WiFiInputMethod started");
    serviceConnection = new ServiceConnection() {

        public void onServiceConnected(ComponentName name, IBinder service) {
            //        Debug.d("WiFiInputMethod connected to HttpService.");
            try {
                remoteKeyboard = RemoteKeyboard.Stub.asInterface(service);
                keyboardListener = new RemoteKeyListener.Stub() {

                    @Override
                    public void keyEvent(int code, boolean pressed) throws RemoteException {
                        // Debug.d("got key in WiFiInputMethod");
                        receivedKey(code, pressed);
                    }

                    @Override
                    public void charEvent(int code) throws RemoteException {
                        // Debug.d("got key in WiFiInputMethod");
                        receivedChar(code);
                    }

                    @Override
                    public boolean setText(String text) throws RemoteException {
                        return WiFiInputMethod.this.setText(text);
                    }

                    @Override
                    public String getText() throws RemoteException {
                        return WiFiInputMethod.this.getText();
                    }
                };
                RemoteKeyboard.Stub.asInterface(service).registerKeyListener(keyboardListener);
            } catch (RemoteException e) {
                throw new RuntimeException("WiFiInputMethod failed to connected to HttpService.", e);
            }
        }

        //@Override
        public void onServiceDisconnected(ComponentName name) {
        //        Debug.d("WiFiInputMethod disconnected from HttpService.");
        }
    };
    if (this.bindService(new Intent(this, HttpService.class), serviceConnection, BIND_AUTO_CREATE) == false) {
        throw new RuntimeException("failed to connect to HttpService");
    }
}
Also used : PowerManager(android.os.PowerManager) ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Stub(com.volosyukivan.RemoteKeyListener.Stub) ComponentName(android.content.ComponentName) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Example 88 with PowerManager

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

the class MediaPlayer method setWakeMode.

/**
     * Set the low-level power management behavior for this MediaPlayer.  This
     * can be used when the MediaPlayer is not playing through a SurfaceHolder
     * set with {@link #setDisplay(SurfaceHolder)} and thus can use the
     * high-level {@link #setScreenOnWhilePlaying(boolean)} feature.
     *
     * <p>This function has the MediaPlayer access the low-level power manager
     * service to control the device's power usage while playing is occurring.
     * The parameter is a combination of {@link android.os.PowerManager} wake flags.
     * Use of this method requires {@link android.Manifest.permission#WAKE_LOCK}
     * permission.
     * By default, no attempt is made to keep the device awake during playback.
     *
     * @param context the Context to use
     * @param mode    the power/wake mode to set
     * @see android.os.PowerManager
     */
public void setWakeMode(Context context, int mode) {
    boolean washeld = false;
    /* Disable persistant wakelocks in media player based on property */
    if (SystemProperties.getBoolean("audio.offload.ignore_setawake", false) == true) {
        Log.w(TAG, "IGNORING setWakeMode " + mode);
        return;
    }
    if (mWakeLock != null) {
        if (mWakeLock.isHeld()) {
            washeld = true;
            mWakeLock.release();
        }
        mWakeLock = null;
    }
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(mode | PowerManager.ON_AFTER_RELEASE, MediaPlayer.class.getName());
    mWakeLock.setReferenceCounted(false);
    if (washeld) {
        mWakeLock.acquire();
    }
}
Also used : PowerManager(android.os.PowerManager)

Example 89 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 90 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)

Aggregations

PowerManager (android.os.PowerManager)289 IntentFilter (android.content.IntentFilter)50 Intent (android.content.Intent)44 Handler (android.os.Handler)33 RemoteException (android.os.RemoteException)31 PendingIntent (android.app.PendingIntent)29 HandlerThread (android.os.HandlerThread)26 Context (android.content.Context)24 IPowerManager (android.os.IPowerManager)21 View (android.view.View)19 Resources (android.content.res.Resources)15 AlarmManager (android.app.AlarmManager)11 SharedPreferences (android.content.SharedPreferences)11 TextView (android.widget.TextView)11 NotificationCompat (android.support.v4.app.NotificationCompat)10 ComponentName (android.content.ComponentName)9 KeyguardManager (android.app.KeyguardManager)8 Vibrator (android.os.Vibrator)8 MotionEvent (android.view.MotionEvent)8 ContentResolver (android.content.ContentResolver)7