Skip to content

Commit 246b8c9

Browse files
committed
Android 10 以降かつManagerがバックグラウンド状態の場合、通話待受モード設定時、権限許可画面が表示されない問題に対応。
1 parent 86503bf commit 246b8c9

1 file changed

Lines changed: 35 additions & 17 deletions

File tree

  • dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostPhoneProfile.java

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import android.os.Looper;
2020
import android.os.ResultReceiver;
2121
import androidx.annotation.NonNull;
22+
23+
import android.provider.Settings;
2224
import android.telecom.TelecomManager;
2325
import android.telephony.TelephonyManager;
2426

@@ -148,23 +150,18 @@ public boolean onRequest(final Intent request, final Intent response) {
148150
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
149151
&& !notificationManager.isNotificationPolicyAccessGranted()) {
150152

151-
Intent intent = new Intent(
152-
android.provider.Settings
153-
.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
154-
155-
IntentHandlerActivity.startActivityForResult(getContext(), intent,
156-
new ResultReceiver(new Handler(Looper.getMainLooper())) {
157-
@Override
158-
protected void onReceiveResult(final int resultCode, final Bundle resultData) {
159-
if (notificationManager.isNotificationPolicyAccessGranted()) {
160-
setPhoneMode(response, mode);
161-
} else {
162-
MessageUtils.setIllegalServerStateError(response,
163-
"PHOME_MODE setting permisson not granted");
164-
}
165-
sendResponse(response);
166-
}
167-
});
153+
requestNotificationPolicyPermission(new ResultReceiver(new Handler(Looper.getMainLooper())) {
154+
@Override
155+
protected void onReceiveResult(final int resultCode, final Bundle resultData) {
156+
if (notificationManager.isNotificationPolicyAccessGranted()) {
157+
setPhoneMode(response, mode);
158+
} else {
159+
MessageUtils.setIllegalServerStateError(response,
160+
"PHOME_MODE setting permisson not granted");
161+
}
162+
sendResponse(response);
163+
}
164+
});
168165
return false;
169166
}
170167
setPhoneMode(response, mode);
@@ -173,6 +170,27 @@ protected void onReceiveResult(final int resultCode, final Bundle resultData) {
173170
}
174171
};
175172

173+
private void requestNotificationPolicyPermission(final ResultReceiver resultReceiver) {
174+
Intent intent = new Intent(
175+
android.provider.Settings
176+
.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
177+
178+
Intent callIntent = new Intent(getContext(), IntentHandlerActivity.class);
179+
callIntent.putExtra("EXTRA_INTENT", intent);
180+
callIntent.putExtra("EXTRA_CALLBACK", resultReceiver);
181+
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
182+
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
183+
184+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
185+
NotificationUtils.createNotificationChannel(getContext());
186+
NotificationUtils.notify(getContext(), NOTIFICATION_ID, 0, callIntent,
187+
getContext().getString(R.string.host_notification_setting_warnning));
188+
} else {
189+
getContext().startActivity(callIntent);
190+
}
191+
}
192+
193+
176194
private void setPhoneMode(Intent response, PhoneMode mode) {
177195
// AudioManager
178196
AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);

0 commit comments

Comments
 (0)