|
@@ -1,5 +1,6 @@
|
|
|
package com.dbs.mplus.fatima;
|
|
|
|
|
|
+import androidx.annotation.Nullable;
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
import android.Manifest;
|
|
@@ -8,6 +9,8 @@ import android.content.Intent;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
+import android.os.PowerManager;
|
|
|
+import android.provider.Settings;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
|
|
@@ -177,7 +180,8 @@ public class MainActivity extends AppCompatActivity {
|
|
|
PermissionListener permissionListener = new PermissionListener() {
|
|
|
@Override
|
|
|
public void onPermissionGranted() {
|
|
|
- nextActivity();
|
|
|
+// nextActivity();
|
|
|
+ whiteListCheck();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -193,6 +197,53 @@ public class MainActivity extends AppCompatActivity {
|
|
|
.check();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 앱 배터리 사용량 최적화 모드 체크
|
|
|
+ * 최적화 모드 중지될 때 까지 무한루프
|
|
|
+ * 최적화 모드가 중지되었다면 기존 로직을 수행
|
|
|
+ * 2020.12.16
|
|
|
+ * jmRyu
|
|
|
+ * Start
|
|
|
+ */
|
|
|
+ private void whiteListCheck() {
|
|
|
+ PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
|
+ // 패키지 명으로 최적화 모드 사용 여부 체크 ( 최적화 모드 사용 상태 = false, 최적화 모드 중지 상태 = true )
|
|
|
+ boolean isPowered = powerManager.isIgnoringBatteryOptimizations(mContext.getPackageName());
|
|
|
+ if (isPowered) {
|
|
|
+ nextActivity();
|
|
|
+ } else {
|
|
|
+ setWhiteList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 배터리 사용량 최적화 중지 System Setting Alert 호출
|
|
|
+ */
|
|
|
+ private void setWhiteList() {
|
|
|
+ csAlert.show();
|
|
|
+ csAlert.setContent(mContext.getString(R.string.whiteList), ConsentConfig.ALERT_BTN_TYPE);
|
|
|
+ csAlert.btnConfirm2.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ csAlert.dismiss();
|
|
|
+ Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
|
|
+ intent.setData(Uri.parse("package:" + mContext.getPackageName()));
|
|
|
+ startActivityForResult(intent, 0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * System Setting Alert 에서 result 를 받았을때 다시 체크로직 수행
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+
|
|
|
+ if (requestCode == 0) {
|
|
|
+ whiteListCheck();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private void nextActivity() {
|
|
|
|