Search in sources :

Example 1 with PowerManager

use of android.os.PowerManager in project cw-omnibus by commonsguy.

the class EventDemoActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
        String pkg = getPackageName();
        PowerManager pm = getSystemService(PowerManager.class);
        if (!pm.isIgnoringBatteryOptimizations(pkg)) {
            Intent i = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).setData(Uri.parse("package:" + pkg));
            startActivity(i);
        }
    }
    if (getFragmentManager().findFragmentById(android.R.id.content) == null) {
        getFragmentManager().beginTransaction().add(android.R.id.content, new EventLogFragment()).commit();
        startService(new Intent(this, ScheduledService.class));
    }
}
Also used : PowerManager(android.os.PowerManager) Intent(android.content.Intent)

Example 2 with PowerManager

use of android.os.PowerManager in project cw-omnibus by commonsguy.

the class ScheduledService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    PowerManager mgr = (PowerManager) getSystemService(POWER_SERVICE);
    wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getSimpleName());
    wakeLock.acquire();
    if (BuildConfig.IS_FOREGROUND) {
        foregroundify();
    }
    log = new File(getExternalFilesDir(null), "antidoze-log.txt");
    log.getParentFile().mkdirs();
    sched.scheduleAtFixedRate(this, 0, 15, TimeUnit.SECONDS);
}
Also used : PowerManager(android.os.PowerManager) File(java.io.File)

Example 3 with PowerManager

use of android.os.PowerManager in project AndroidTraining by mixi-inc.

the class DefaultModule method configure.

@SuppressWarnings("unchecked")
protected void configure() {
    bind(Application.class).toProvider(ApplicationProvider.class).in(ApplicationScoped.class);
    bind(Context.class).toProvider(ContextProvider.class);
    bind(Handler.class).toProvider(HandlerProvider.class).in(ApplicationScoped.class);
    bind(ActivityManager.class).toProvider(new SystemServiceProvider<ActivityManager>(Context.ACTIVITY_SERVICE));
    bind(AlarmManager.class).toProvider(new SystemServiceProvider<AlarmManager>(Context.ALARM_SERVICE));
    bind(AudioManager.class).toProvider(new SystemServiceProvider<AudioManager>(Context.AUDIO_SERVICE));
    bind(ConnectivityManager.class).toProvider(new SystemServiceProvider<ConnectivityManager>(Context.CONNECTIVITY_SERVICE));
    bind(InputMethodManager.class).toProvider(new SystemServiceProvider<InputMethodManager>(Context.INPUT_METHOD_SERVICE));
    bind(KeyguardManager.class).toProvider(new SystemServiceProvider<KeyguardManager>(Context.KEYGUARD_SERVICE));
    bind(LocationManager.class).toProvider(new SystemServiceProvider<LocationManager>(Context.LOCATION_SERVICE));
    bind(NotificationManager.class).toProvider(new SystemServiceProvider<NotificationManager>(Context.NOTIFICATION_SERVICE));
    bind(PowerManager.class).toProvider(new SystemServiceProvider<PowerManager>(Context.POWER_SERVICE));
    bind(SensorManager.class).toProvider(new SystemServiceProvider<SensorManager>(Context.SENSOR_SERVICE));
    bind(TelephonyManager.class).toProvider(new SystemServiceProvider<TelephonyManager>(Context.TELEPHONY_SERVICE));
    bind(Vibrator.class).toProvider(new SystemServiceProvider<Vibrator>(Context.VIBRATOR_SERVICE));
    bind(WifiManager.class).toProvider(new SystemServiceProvider<WifiManager>(Context.WIFI_SERVICE));
    bind(WindowManager.class).toProvider(new SystemServiceProvider<WindowManager>(Context.WINDOW_SERVICE));
    bind(mAccountManagerClass).toProvider(AccountManagerProvider.class);
    bind(ObserverManager.class);
    bindProviderListener(new ObserverRegister());
    bind(StateManager.class).in(ApplicationScoped.class);
    bind(StateEventObserver.class);
    bindFieldListener(RetainState.class, new RetainStateListener());
}
Also used : WifiManager(android.net.wifi.WifiManager) ConnectivityManager(android.net.ConnectivityManager) InputMethodManager(android.view.inputmethod.InputMethodManager) ActivityManager(android.app.ActivityManager) WindowManager(android.view.WindowManager) PowerManager(android.os.PowerManager) AudioManager(android.media.AudioManager) StateManager(proton.inject.state.StateManager) TelephonyManager(android.telephony.TelephonyManager) Context(android.content.Context) LocationManager(android.location.LocationManager) ApplicationProvider(proton.inject.provider.ApplicationProvider) NotificationManager(android.app.NotificationManager) HandlerProvider(proton.inject.provider.HandlerProvider) RetainStateListener(proton.inject.state.RetainStateListener) SensorManager(android.hardware.SensorManager) AlarmManager(android.app.AlarmManager) Vibrator(android.os.Vibrator) KeyguardManager(android.app.KeyguardManager) ObserverRegister(proton.inject.observer.ObserverRegister)

Example 4 with PowerManager

use of android.os.PowerManager in project k-9 by k9mail.

the class K9AlarmManagerTest method createK9AlarmManagerWithDozeSupport.

private K9AlarmManager createK9AlarmManagerWithDozeSupport(boolean whiteListed) {
    PowerManager powerManager = createPowerManager(whiteListed);
    Context context = createContext(powerManager);
    return new TestK9AlarmManager(context, true);
}
Also used : PowerManager(android.os.PowerManager) Context(android.content.Context)

Example 5 with PowerManager

use of android.os.PowerManager in project qksms by moezbhatti.

the class MessagingReceiver method insertMessageAndNotify.

private void insertMessageAndNotify() {
    mUri = SmsHelper.addMessageToInbox(mContext, mAddress, mBody, mDate);
    Message message = new Message(mContext, mUri);
    ConversationPrefsHelper conversationPrefs = new ConversationPrefsHelper(mContext, message.getThreadId());
    // we can block it, so that the conversation list adapter knows to ignore this thread in the main list
    if (BlockedConversationHelper.isFutureBlocked(mPrefs, mAddress)) {
        BlockedConversationHelper.unblockFutureConversation(mPrefs, mAddress);
        BlockedConversationHelper.blockConversation(mPrefs, message.getThreadId());
        message.markSeen();
        BlockedConversationHelper.FutureBlockedConversationObservable.getInstance().futureBlockedConversationReceived();
    // If we have notifications enabled and this conversation isn't blocked
    } else if (conversationPrefs.getNotificationsEnabled() && !BlockedConversationHelper.getBlockedConversationIds(PreferenceManager.getDefaultSharedPreferences(mContext)).contains(message.getThreadId())) {
        Intent messageHandlerIntent = new Intent(mContext, NotificationService.class);
        messageHandlerIntent.putExtra(NotificationService.EXTRA_POPUP, true);
        messageHandlerIntent.putExtra(NotificationService.EXTRA_URI, mUri.toString());
        mContext.startService(messageHandlerIntent);
        UnreadBadgeService.update(mContext);
        NotificationManager.create(mContext);
    } else {
        // We shouldn't show a notification for this message
        message.markSeen();
    }
    if (conversationPrefs.getWakePhoneEnabled()) {
        PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "MessagingReceiver");
        wakeLock.acquire();
        wakeLock.release();
    }
}
Also used : PowerManager(android.os.PowerManager) SmsMessage(android.telephony.SmsMessage) Message(com.moez.QKSMS.data.Message) Intent(android.content.Intent) NotificationService(com.moez.QKSMS.service.NotificationService) ConversationPrefsHelper(com.moez.QKSMS.common.ConversationPrefsHelper)

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