Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
R repo_manifest
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • scorpio
  • repo_manifest
  • Wiki
  • poweroff screen recovery

Last edited by Mark Stevens Jun 08, 2018
Page history

poweroff screen recovery

PowerOff screen recovery :

/**
 * Usage :
 *
 * onResume()
 * mScreenOffWakeupReceiver = new ScreenOffWakeupReceiver();
 * // optional if we should return to a specific activity
 * mScreenOffWakeupReceiver.setWakeupActivity( getPackageManager().getLaunchIntentForPackage(getPackageName()));
 * registerReceiver(mScreenOffWakeupReceiver, mScreenOffWakeupReceiver.getFilters());
 *
 * onPause()
 * if (mScreenOffWakeupReceiver!=null)
 *    unregisterReceiver( mScreenOffWakeupReceiver );
 *
 *    Requires Permission:   android.permission.WAKE_LOCK

 */
public class ScreenOffWakeupReceiver extends BroadcastReceiver {
    private static final String TAG = "ScreenOffWakeupRcvr";
    public static final String ACTION_COLD_WATER = "com.buzztime.intent.action.COLD_WATER";
    private static Intent wakeupIntent = null;

    public void setWakeupActivity( Intent intent ){
        wakeupIntent = new Intent(intent);
        wakeupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NEW_TASK);
    }

    public IntentFilter getFilters() {
        return new IntentFilter(){{
            addAction(Intent.ACTION_SCREEN_OFF);
            addAction(ACTION_COLD_WATER);
        }};
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.d(TAG, action);

        if (Intent.ACTION_SCREEN_OFF.equals(action)) {

            // Screen off indicated..
            // Use AlarmManager to wake the unit up again
            Intent i = new Intent(ACTION_COLD_WATER)
                .setClass(context, ScreenOffWakeupReceiver.class);
            PendingIntent sender = PendingIntent.getBroadcast(context, 192837, i, PendingIntent.FLAG_UPDATE_CURRENT);

            // Get the AlarmManager service
            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            if (Build.VERSION.SDK_INT >= 23 ){
                am.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 500, sender);
            } else
            if (Build.VERSION.SDK_INT >= 19){
                am.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 750, sender);
            } else {
                am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 500, sender);
            }

        } else if (ACTION_COLD_WATER.equals(action)) {
            // after a short pause, AlarmManager will wake us up and let us run our activity
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            if (!pm.isInteractive()) {
                PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
                    | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE , "wlKiosk");
                wl.acquire(10000);
                PowerManager.WakeLock wlCpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "wlKioskCpu");
                wlCpu.acquire(10000);
                wlCpu.release();
            }

            if (wakeupIntent!=null) {
                context.startActivity( wakeupIntent );
            }

        }
    }
}
Clone repository
  • bootanimation customization
  • bootanimations
  • build ota images
  • control all apps button in launcher
  • Home
  • iptables (pci review)
  • poweroff screen recovery
  • usb tethering