Android 开机向导界面,如果超过10分钟,自动关机 代码 demo

Android 开机向导界面,如果超过10分钟,自动关机 代码 demo
在Settings 模块里面添加如下代码:
package com.android.settings.sim.receivers

git diff 如下

diff --git a/src/com/android/settings/sim/receivers/SimCompleteBootReceiver.java b/src/com/android/settings/sim/receivers/SimCompleteBootReceiver.java
index a7c9ecf..8777339 100644
--- a/src/com/android/settings/sim/receivers/SimCompleteBootReceiver.java
+++ b/src/com/android/settings/sim/receivers/SimCompleteBootReceiver.java
@@ -19,12 +19,15 @@ package com.android.settings.sim.receivers;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
+import android.os.CountDownTimer;
 import android.util.Log;
 
 import com.android.settings.hnlens.display.TouchSensitivityPreferenceController;
 import com.android.settings.sim.SimActivationNotifier;
 import com.android.settings.sim.SimNotificationService;
 
+import com.google.android.setupcompat.util.WizardManagerHelper;
+
 /** This class manage all SIM operations after device boot up. */
 public class SimCompleteBootReceiver extends BroadcastReceiver {
     private static final String TAG = "SimCompleteBootReceiver";
@@ -39,8 +42,50 @@ public class SimCompleteBootReceiver extends BroadcastReceiver {
             SimNotificationService.scheduleSimNotification(
                     context, SimActivationNotifier.NotificationType.NETWORK_CONFIG);
         }

+
+        //check setupwarized
+        if (WizardManagerHelper.isUserSetupComplete(context)){
+            Log.i(TAG, "onReceive: WizardManagerHelper isUserSetupComplete");
+        }else {
+            Log.i(TAG, "onReceive: WizardManagerHelper not com");
+            startCountdown(context);
+        }
     }
+
+    private CountDownTimer countDownTimer;
+    private final long totalTime = 5 * 60 * 1000; // 10 minutes in milliseconds
+    private void startCountdown(final  Context context) {
+        countDownTimer = new CountDownTimer(totalTime, 1000*60) {
+            @Override
+            public void onTick(long millisUntilFinished) {
+                long seconds = millisUntilFinished / 1000;
+                Log.i(TAG, "onReceive: countDownTimer ticker "+seconds);
+                //tvCountdown.setText(String.format(Locale.getDefault(), "%02d:%02d", seconds / 60, seconds % 60));
+                if (WizardManagerHelper.isUserSetupComplete(context)){
+                    countDownTimer.cancel();
+                    Log.i(TAG, "onReceive: countDownTimer cancel ");
+                }
+            }
+
+            @Override
+            public void onFinish() {
+                if (!WizardManagerHelper.isUserSetupComplete(context)){
+                    shutdownDevice(context);
+                }
+            }
+        }.start();
+    }
+
+    private void shutdownDevice(final  Context context) {
+        String ACTION_REQUEST_SHUTDOWN = "com.android.internal.intent.action.REQUEST_SHUTDOWN";
+        Intent shutdownIntent = new Intent(ACTION_REQUEST_SHUTDOWN);
+        shutdownIntent.putExtra("android.intent.extra.KEY_CONFIRM", false);
+        shutdownIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        context.startActivity(shutdownIntent);
+    }
+
 }

在packages/apps/Settings
patch -p0 < xxx.diff

你可能感兴趣的:(android,setupwizard,java)