33import android .animation .Animator ;
44import android .animation .ObjectAnimator ;
55import android .annotation .SuppressLint ;
6+ import android .content .ActivityNotFoundException ;
67import android .content .Context ;
78import android .content .Intent ;
89import android .graphics .Canvas ;
1617import android .os .Process ;
1718import android .os .RemoteException ;
1819import android .os .SystemClock ;
20+ import android .preference .PreferenceManager ;
1921import android .provider .Settings ;
2022import android .support .annotation .Nullable ;
2123import android .support .v7 .app .AlertDialog ;
@@ -72,6 +74,8 @@ public class HomeActivity extends VActivity implements HomeContract.HomeView {
7274
7375 private static final String TAG = HomeActivity .class .getSimpleName ();
7476
77+ private static final String SHOW_DOZE_ALERT_KEY = "SHOW_DOZE_ALERT_KEY" ;
78+
7579 private HomeContract .HomePresenter mPresenter ;
7680 private TwoGearsView mLoadingView ;
7781 private RecyclerView mLauncherView ;
@@ -697,6 +701,10 @@ private void alertForDoze() {
697701 if (powerManager == null ) {
698702 return ;
699703 }
704+ boolean showAlert = PreferenceManager .getDefaultSharedPreferences (this ).getBoolean (SHOW_DOZE_ALERT_KEY , true );
705+ if (!showAlert ) {
706+ return ;
707+ }
700708 String packageName = getPackageName ();
701709 boolean ignoringBatteryOptimizations = powerManager .isIgnoringBatteryOptimizations (packageName );
702710 if (!ignoringBatteryOptimizations ) {
@@ -707,12 +715,23 @@ private void alertForDoze() {
707715 .setMessage (R .string .alert_for_doze_mode_content )
708716 .setPositiveButton (R .string .alert_for_doze_mode_yes , (dialog , which ) -> {
709717 try {
710- startActivity (new Intent (Settings .ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS ,
711- Uri .parse ("package:" + packageName )));
712- } catch (Throwable ignored ) {
718+ startActivity (new Intent (Settings .ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS , Uri .parse ("package:" + getPackageName ())));
719+ } catch (ActivityNotFoundException ignored ) {
713720 // ActivityNotFoundException on some devices.
721+ try {
722+ startActivity (new Intent (Settings .ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS ));
723+ } catch (Throwable e ) {
724+ PreferenceManager .getDefaultSharedPreferences (HomeActivity .this )
725+ .edit ().putBoolean (SHOW_DOZE_ALERT_KEY , false ).apply ();
726+ }
727+ } catch (Throwable e ) {
728+ PreferenceManager .getDefaultSharedPreferences (HomeActivity .this )
729+ .edit ().putBoolean (SHOW_DOZE_ALERT_KEY , false ).apply ();
714730 }
715731 })
732+ .setNegativeButton (R .string .alert_for_doze_mode_no , (dialog , which ) ->
733+ PreferenceManager .getDefaultSharedPreferences (HomeActivity .this )
734+ .edit ().putBoolean (SHOW_DOZE_ALERT_KEY , false ).apply ())
716735 .create ();
717736 try {
718737 alertDialog .show ();
0 commit comments