Skip to content

Commit 86503bf

Browse files
committed
Android 10 以降、画面の明るさ設定時、システム設定の画面が表示されない問題に対応。
1 parent fc9190c commit 86503bf

3 files changed

Lines changed: 35 additions & 14 deletions

File tree

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

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99

1010
import org.deviceconnect.android.activity.IntentHandlerActivity;
11+
import org.deviceconnect.android.deviceplugin.host.R;
1112
import org.deviceconnect.android.message.MessageUtils;
1213
import org.deviceconnect.android.profile.SettingProfile;
1314
import org.deviceconnect.android.profile.api.DConnectApi;
1415
import org.deviceconnect.android.profile.api.GetApi;
1516
import org.deviceconnect.android.profile.api.PutApi;
17+
import org.deviceconnect.android.util.NotificationUtils;
1618
import org.deviceconnect.message.DConnectMessage;
1719
import org.deviceconnect.utils.RFC3339DateUtils;
1820

@@ -37,6 +39,7 @@ public class HostSettingProfile extends SettingProfile {
3739
/** Light Levelの最大値. */
3840
private static final int MAX_LIGHT_LEVEL = 255;
3941

42+
private final int NOTIFICATION_ID = 4000;
4043

4144
private final DConnectApi mGetSoundVolumeApi = new GetApi() {
4245

@@ -223,21 +226,18 @@ public boolean onRequest(final Intent request, final Intent response) {
223226
if (Settings.System.canWrite(getContext())) {
224227
onPutDisplayLightInternal(request, response, serviceId, level);
225228
} else {
226-
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
227-
Uri.parse("package:" + getContext().getPackageName()));
228-
IntentHandlerActivity.startActivityForResult(getContext(), intent,
229-
new ResultReceiver(new Handler(Looper.getMainLooper())) {
230-
@Override
231-
protected void onReceiveResult(final int resultCode, final Bundle resultData) {
232-
if (Settings.System.canWrite(getContext())) {
233-
onPutDisplayLightInternal(request, response, serviceId, level);
234-
} else {
235-
MessageUtils.setIllegalServerStateError(response,
229+
requestSystemSettingPermission(new ResultReceiver(new Handler(Looper.getMainLooper())) {
230+
@Override
231+
protected void onReceiveResult(final int resultCode, final Bundle resultData) {
232+
if (Settings.System.canWrite(getContext())) {
233+
onPutDisplayLightInternal(request, response, serviceId, level);
234+
} else {
235+
MessageUtils.setIllegalServerStateError(response,
236236
"WRITE_SETTINGS permisson not granted");
237-
}
238-
sendResponse(response);
239237
}
240-
});
238+
sendResponse(response);
239+
}
240+
});
241241
return false;
242242
}
243243
} else {
@@ -247,6 +247,25 @@ protected void onReceiveResult(final int resultCode, final Bundle resultData) {
247247
}
248248
};
249249

250+
private void requestSystemSettingPermission(final ResultReceiver resultReceiver) {
251+
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
252+
Uri.parse("package:" + getContext().getPackageName()));
253+
254+
Intent callIntent = new Intent(getContext(), IntentHandlerActivity.class);
255+
callIntent.putExtra("EXTRA_INTENT", intent);
256+
callIntent.putExtra("EXTRA_CALLBACK", resultReceiver);
257+
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
258+
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
259+
260+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
261+
NotificationUtils.createNotificationChannel(getContext());
262+
NotificationUtils.notify(getContext(), NOTIFICATION_ID, 0, callIntent,
263+
getContext().getString(R.string.host_notification_setting_warnning));
264+
} else {
265+
getContext().startActivity(callIntent);
266+
}
267+
}
268+
250269
private final DConnectApi mPutDisplaySleepApi = new PutApi() {
251270
@Override
252271
public boolean onRequest(final Intent request, final Intent response) {

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/res/values-ja/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,6 @@
117117
<string name="host_notification_geolocation_warnning">Host Geolocation Profileからの起動要求</string>
118118
<string name="host_notification_connection_warnning">Host Connection Profileからの起動要求</string>
119119
<string name="host_notification_projection_warnning">Host Media Streaming Recording Profileからの起動要求</string>
120-
<string name="host_notification_phone_warnning">Host Connection Profileからの起動要求</string>
120+
<string name="host_notification_phone_warnning">Host Phone Profileからの起動要求</string>
121+
<string name="host_notification_setting_warnning">Host Setting Profileからの起動要求</string>
121122
</resources>

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,6 @@
131131
<string name="host_notification_connection_warnning">Start request from Host Connection Profile</string>
132132
<string name="host_notification_projection_warnning">Start request from Host Media Streaming Recording Profile</string>
133133
<string name="host_notification_phone_warnning">Start request from Host Phone Profile</string>
134+
<string name="host_notification_setting_warnning">Start request from Host Setting Profile</string>
134135
</resources>
135136

0 commit comments

Comments
 (0)