Skip to content

Commit acf2afb

Browse files
author
tiann
committed
[Exposed-core] Add alertForDoze & alertForMeizu.
1 parent 335c0c2 commit acf2afb

File tree

1 file changed

+83
-1
lines changed

1 file changed

+83
-1
lines changed

VirtualApp/app/src/main/java/io/virtualapp/home/NewHomeActivity.java

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
package io.virtualapp.home;
22

33
import android.app.Activity;
4+
import android.content.ActivityNotFoundException;
45
import android.content.ComponentName;
56
import android.content.Context;
67
import android.content.Intent;
8+
import android.net.Uri;
9+
import android.os.Build;
710
import android.os.Bundle;
811
import android.os.Handler;
12+
import android.os.PowerManager;
913
import android.os.SystemClock;
14+
import android.preference.PreferenceManager;
15+
import android.provider.Settings;
16+
import android.support.v7.app.AlertDialog;
1017
import android.text.TextUtils;
1118
import android.view.View;
1219
import android.widget.Toast;
1320

1421
import com.google.android.apps.nexuslauncher.NexusLauncherActivity;
22+
import com.lody.virtual.client.core.VirtualCore;
23+
import com.lody.virtual.helper.utils.DeviceUtil;
1524

1625
import java.io.File;
1726
import java.util.List;
1827
import java.util.concurrent.TimeUnit;
1928

2029
import io.virtualapp.R;
30+
import io.virtualapp.VApp;
2131
import io.virtualapp.VCommends;
2232
import io.virtualapp.home.models.AppData;
2333
import io.virtualapp.home.models.AppInfoLite;
@@ -30,10 +40,11 @@
3040

3141
public class NewHomeActivity extends NexusLauncherActivity implements HomeContract.HomeView {
3242

43+
private static final String SHOW_DOZE_ALERT_KEY = "SHOW_DOZE_ALERT_KEY";
44+
3345
private HomeContract.HomePresenter mPresenter;
3446
private Handler mUiHandler;
3547
private int mInstallCount = 0;
36-
private long mInstallStartTime;
3748

3849

3950
@Override
@@ -45,6 +56,9 @@ protected void onCreate(Bundle savedInstanceState) {
4556
getHotseat().setSettingClickListener(v -> onSettingsClicked());
4657

4758
new HomePresenterImpl(this).start();
59+
60+
alertForMeizu();
61+
alertForDoze();
4862
}
4963

5064
@Override
@@ -204,4 +218,72 @@ private void refreshLoadingDialog(AppData model) {
204218
}
205219
});
206220
}
221+
222+
private void alertForMeizu() {
223+
if (!DeviceUtil.isMeizuBelowN()) {
224+
return;
225+
}
226+
boolean isXposedInstalled = VirtualCore.get().isAppInstalled(VApp.XPOSED_INSTALLER_PACKAGE);
227+
if (isXposedInstalled) {
228+
return;
229+
}
230+
mUiHandler.postDelayed(() -> {
231+
AlertDialog alertDialog = new AlertDialog.Builder(getContext())
232+
.setTitle(R.string.meizu_device_tips_title)
233+
.setMessage(R.string.meizu_device_tips_content)
234+
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
235+
})
236+
.create();
237+
try {
238+
alertDialog.show();
239+
} catch (Throwable ignored) {}
240+
}, 2000);
241+
}
242+
243+
private void alertForDoze() {
244+
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
245+
return;
246+
}
247+
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
248+
if (powerManager == null) {
249+
return;
250+
}
251+
boolean showAlert = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(SHOW_DOZE_ALERT_KEY, true);
252+
if (!showAlert) {
253+
return;
254+
}
255+
String packageName = getPackageName();
256+
boolean ignoringBatteryOptimizations = powerManager.isIgnoringBatteryOptimizations(packageName);
257+
if (!ignoringBatteryOptimizations) {
258+
259+
mUiHandler.postDelayed(() -> {
260+
AlertDialog alertDialog = new AlertDialog.Builder(getContext())
261+
.setTitle(R.string.alert_for_doze_mode_title)
262+
.setMessage(R.string.alert_for_doze_mode_content)
263+
.setPositiveButton(R.string.alert_for_doze_mode_yes, (dialog, which) -> {
264+
try {
265+
startActivity(new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:" + getPackageName())));
266+
} catch (ActivityNotFoundException ignored) {
267+
// ActivityNotFoundException on some devices.
268+
try {
269+
startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));
270+
} catch (Throwable e) {
271+
PreferenceManager.getDefaultSharedPreferences(getActivity())
272+
.edit().putBoolean(SHOW_DOZE_ALERT_KEY, false).apply();
273+
}
274+
} catch (Throwable e) {
275+
PreferenceManager.getDefaultSharedPreferences(getActivity())
276+
.edit().putBoolean(SHOW_DOZE_ALERT_KEY, false).apply();
277+
}
278+
})
279+
.setNegativeButton(R.string.alert_for_doze_mode_no, (dialog, which) ->
280+
PreferenceManager.getDefaultSharedPreferences(getActivity())
281+
.edit().putBoolean(SHOW_DOZE_ALERT_KEY, false).apply())
282+
.create();
283+
try {
284+
alertDialog.show();
285+
} catch (Throwable ignored) {}
286+
}, 3000);
287+
}
288+
}
207289
}

0 commit comments

Comments
 (0)