mirror of
https://github.com/adolfintel/OpenPods.git
synced 2026-09-14 14:56:11 -04:00
Android 12 support (for real this time)
This commit is contained in:
@@ -2,15 +2,15 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.dosse.airpods">
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.bluetooth_le"
|
||||
|
||||
@@ -23,6 +23,8 @@ public class IntroActivity extends AppCompatActivity {
|
||||
private TextView msg;
|
||||
private Button btn;
|
||||
|
||||
private static final int STEP_PERMISSION_BLUETOOTH_SCAN = 1, STEP_PERMISSION_BLUETOOTH_CONNECT = 2, STEP_PERMISSION_BATTERY_OPTIMIZATION = 3, STEP_PERMISSION_LOCATION = 4, STEP_PERMISSION_BACKGROUND_LOCATION = 5;
|
||||
|
||||
@Override
|
||||
protected void onCreate (Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -58,26 +60,40 @@ public class IntroActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private int getPermissionState () {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) if (!PermissionUtils.getBluetoothPermissions(this))
|
||||
return 1;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) if (!PermissionUtils.getBluetoothScanPermission(this))
|
||||
return STEP_PERMISSION_BLUETOOTH_SCAN;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) if (!PermissionUtils.getBluetoothConnectPermission(this))
|
||||
return STEP_PERMISSION_BLUETOOTH_CONNECT;
|
||||
if (!PermissionUtils.getBatteryOptimizationsPermission(this))
|
||||
return 2;
|
||||
return STEP_PERMISSION_BATTERY_OPTIMIZATION;
|
||||
if (!PermissionUtils.getFineLocationPermission(this))
|
||||
return 3;
|
||||
return STEP_PERMISSION_LOCATION;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) if (!PermissionUtils.getBackgroundLocationPermission(this))
|
||||
return 4;
|
||||
return STEP_PERMISSION_BACKGROUND_LOCATION;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@SuppressLint("BatteryLife")
|
||||
private void initScreen () {
|
||||
int step = getPermissionState() - ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) ? 0 : 1);
|
||||
int numOfSteps = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) ? ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) ? 4 : 3) : 2;
|
||||
int currentStep = getPermissionState() - ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) ? 0 : 2);
|
||||
int numOfSteps = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) ? ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) ? 5 : 3) : 2;
|
||||
|
||||
switch (step) {
|
||||
case 1:
|
||||
msg.setText(String.format(Locale.getDefault(), "%s %d/%d: %s", getString(R.string.intro_step), step, numOfSteps, getString(R.string.intro_bat_perm)));
|
||||
switch (getPermissionState()) {
|
||||
case STEP_PERMISSION_BLUETOOTH_SCAN:
|
||||
msg.setText(String.format(Locale.getDefault(), "%s %d/%d: %s", getString(R.string.intro_step), currentStep, numOfSteps, getString(R.string.intro_bt1_perm)));
|
||||
btn.setOnClickListener(view -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) requestPermissions(new String[] {Manifest.permission.BLUETOOTH_SCAN}, 101);
|
||||
});
|
||||
break;
|
||||
case STEP_PERMISSION_BLUETOOTH_CONNECT:
|
||||
msg.setText(String.format(Locale.getDefault(), "%s %d/%d: %s", getString(R.string.intro_step), currentStep, numOfSteps, getString(R.string.intro_bt2_perm)));
|
||||
btn.setOnClickListener(view -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) requestPermissions(new String[] {Manifest.permission.BLUETOOTH_CONNECT}, 102);
|
||||
});
|
||||
break;
|
||||
case STEP_PERMISSION_BATTERY_OPTIMIZATION:
|
||||
msg.setText(String.format(Locale.getDefault(), "%s %d/%d: %s", getString(R.string.intro_step), currentStep, numOfSteps, getString(R.string.intro_bat_perm)));
|
||||
btn.setOnClickListener(view -> {
|
||||
Intent intent = new Intent();
|
||||
getSystemService(Context.POWER_SERVICE);
|
||||
@@ -86,19 +102,20 @@ public class IntroActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
msg.setText(String.format(Locale.getDefault(), "%s %d/%d: %s", getString(R.string.intro_step), step, numOfSteps, getString(R.string.intro_loc1_perm)));
|
||||
btn.setOnClickListener(view -> requestPermissions(new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, 101)); // Location (for BLE)
|
||||
case STEP_PERMISSION_LOCATION:
|
||||
msg.setText(String.format(Locale.getDefault(), "%s %d/%d: %s", getString(R.string.intro_step), currentStep, numOfSteps, getString(R.string.intro_loc1_perm)));
|
||||
btn.setOnClickListener(view -> requestPermissions(new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, 103)); // Location (for BLE)
|
||||
break;
|
||||
case 3:
|
||||
msg.setText(String.format(Locale.getDefault(), "%s %d/%d: %s", getString(R.string.intro_step), step, numOfSteps, getString(R.string.intro_loc2_perm)));
|
||||
case STEP_PERMISSION_BACKGROUND_LOCATION:
|
||||
msg.setText(String.format(Locale.getDefault(), "%s %d/%d: %s", getString(R.string.intro_step), currentStep, numOfSteps, getString(R.string.intro_loc2_perm)));
|
||||
btn.setOnClickListener(view -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) requestPermissions(new String[] {Manifest.permission.ACCESS_BACKGROUND_LOCATION}, 102);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||
requestPermissions(new String[] {Manifest.permission.ACCESS_BACKGROUND_LOCATION}, 104);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
runOnUiThread(() -> btn.setText(String.format(Locale.getDefault(), "%s (%d/%d)", getString(R.string.intro_allow), step, numOfSteps)));
|
||||
runOnUiThread(() -> btn.setText(String.format(Locale.getDefault(), "%s (%d/%d)", getString(R.string.intro_allow), currentStep, numOfSteps)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,9 +22,13 @@ public class PermissionUtils {
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.S)
|
||||
public static boolean getBluetoothPermissions (Context context) {
|
||||
return ContextCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED
|
||||
&& ContextCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED;
|
||||
public static boolean getBluetoothScanPermission (Context context) {
|
||||
return ContextCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.S)
|
||||
public static boolean getBluetoothConnectPermission (Context context) {
|
||||
return ContextCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
public static boolean getFineLocationPermission (Context context) {
|
||||
@@ -38,7 +42,7 @@ public class PermissionUtils {
|
||||
|
||||
public static boolean checkAllPermissions (Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
||||
return getBatteryOptimizationsPermission(context) && getFineLocationPermission(context) && getBackgroundLocationPermission(context) && getBluetoothPermissions(context);
|
||||
return getBatteryOptimizationsPermission(context) && getFineLocationPermission(context) && getBackgroundLocationPermission(context) && getBluetoothScanPermission(context) && getBluetoothConnectPermission(context);
|
||||
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||
return getBatteryOptimizationsPermission(context) && getFineLocationPermission(context) && getBackgroundLocationPermission(context);
|
||||
else
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
<string name="intro_message">To operate, we need permission to use Bluetooth LE (Location) and permission to run in background</string>
|
||||
<string name="intro_allow">Allow</string>
|
||||
<string name="intro_step" tools:ignore="MissingTranslation">Step</string>
|
||||
<string name="intro_bt1_perm" tools:ignore="MissingTranslation">Bluetooth Scan Permission</string>
|
||||
<string name="intro_bt2_perm" tools:ignore="MissingTranslation">Bluetooth Connect Permission</string>
|
||||
<string name="intro_bat_perm" tools:ignore="MissingTranslation">Battery Optimization</string>
|
||||
<string name="intro_loc1_perm" tools:ignore="MissingTranslation">Location Permission</string>
|
||||
<string name="intro_loc2_perm" tools:ignore="MissingTranslation">Background Location Permission</string>
|
||||
|
||||
Reference in New Issue
Block a user