-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enterprise: user/work profile switch from drawer
- Loading branch information
Showing
16 changed files
with
470 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/AppProfileHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package deckers.thibault.aves.channel.calls | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.pm.CrossProfileApps | ||
import android.os.Build | ||
import deckers.thibault.aves.channel.calls.Coresult.Companion.safe | ||
import io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler | ||
|
||
class AppProfileHandler(private val activity: Activity) : MethodCallHandler { | ||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { | ||
when (call.method) { | ||
"canInteractAcrossProfiles" -> safe(call, result, ::canInteractAcrossProfiles) | ||
"canRequestInteractAcrossProfiles" -> safe(call, result, ::canRequestInteractAcrossProfiles) | ||
"requestInteractAcrossProfiles" -> safe(call, result, ::requestInteractAcrossProfiles) | ||
"switchProfile" -> safe(call, result, ::switchProfile) | ||
"getProfileSwitchingLabel" -> safe(call, result, ::getProfileSwitchingLabel) | ||
"getTargetUserProfiles" -> safe(call, result, ::getTargetUserProfiles) | ||
else -> result.notImplemented() | ||
} | ||
} | ||
|
||
private fun canInteractAcrossProfiles(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { | ||
result.success(false) | ||
return | ||
} | ||
|
||
val crossProfileApps = activity.getSystemService(Context.CROSS_PROFILE_APPS_SERVICE) as CrossProfileApps | ||
result.success(crossProfileApps.canInteractAcrossProfiles()) | ||
} | ||
|
||
private fun canRequestInteractAcrossProfiles(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { | ||
result.success(false) | ||
return | ||
} | ||
|
||
val crossProfileApps = activity.getSystemService(Context.CROSS_PROFILE_APPS_SERVICE) as CrossProfileApps | ||
result.success(crossProfileApps.canRequestInteractAcrossProfiles()) | ||
} | ||
|
||
private fun requestInteractAcrossProfiles(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { | ||
result.success(false) | ||
return | ||
} | ||
|
||
val crossProfileApps = activity.getSystemService(Context.CROSS_PROFILE_APPS_SERVICE) as CrossProfileApps | ||
val intent = crossProfileApps.createRequestInteractAcrossProfilesIntent() | ||
val started = activity.startActivity(intent) | ||
|
||
result.success(started) | ||
} | ||
|
||
private fun switchProfile(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { | ||
result.success(false) | ||
return | ||
} | ||
|
||
val crossProfileApps = activity.getSystemService(Context.CROSS_PROFILE_APPS_SERVICE) as CrossProfileApps | ||
val userHandles = crossProfileApps.targetUserProfiles | ||
crossProfileApps.startMainActivity(activity.componentName, userHandles.first()) | ||
result.success(null) | ||
} | ||
|
||
private fun getProfileSwitchingLabel(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { | ||
result.success(null) | ||
return | ||
} | ||
|
||
val crossProfileApps = activity.getSystemService(Context.CROSS_PROFILE_APPS_SERVICE) as CrossProfileApps | ||
val userHandles = crossProfileApps.targetUserProfiles | ||
val label = crossProfileApps.getProfileSwitchingLabel(userHandles.first()) | ||
|
||
result.success(label) | ||
} | ||
|
||
private fun getTargetUserProfiles(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { | ||
result.success(false) | ||
return | ||
} | ||
|
||
val crossProfileApps = activity.getSystemService(Context.CROSS_PROFILE_APPS_SERVICE) as CrossProfileApps | ||
val userProfiles = crossProfileApps.targetUserProfiles.map { it.toString() }.toList() | ||
result.success(userProfiles) | ||
} | ||
|
||
companion object { | ||
const val CHANNEL = "deckers.thibault/aves/app_profile" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:aves/services/common/services.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
abstract class AppProfileService { | ||
Future<bool> canInteractAcrossProfiles(); | ||
|
||
Future<bool> canRequestInteractAcrossProfiles(); | ||
|
||
Future<bool> requestInteractAcrossProfiles(); | ||
|
||
Future<String> getProfileSwitchingLabel(); | ||
|
||
Future<void> switchProfile(); | ||
|
||
Future<List<String>> getTargetUserProfiles(); | ||
} | ||
|
||
class PlatformAppProfileService implements AppProfileService { | ||
static const _platform = MethodChannel('deckers.thibault/aves/app_profile'); | ||
|
||
@override | ||
Future<bool> canInteractAcrossProfiles() async { | ||
try { | ||
final result = await _platform.invokeMethod('canInteractAcrossProfiles'); | ||
if (result != null) return result as bool; | ||
} on PlatformException catch (e, stack) { | ||
await reportService.recordError(e, stack); | ||
} | ||
return false; | ||
} | ||
|
||
@override | ||
Future<bool> canRequestInteractAcrossProfiles() async { | ||
try { | ||
final result = await _platform.invokeMethod('canRequestInteractAcrossProfiles'); | ||
if (result != null) return result as bool; | ||
} on PlatformException catch (e, stack) { | ||
await reportService.recordError(e, stack); | ||
} | ||
return false; | ||
} | ||
|
||
@override | ||
Future<bool> requestInteractAcrossProfiles() async { | ||
try { | ||
final result = await _platform.invokeMethod('requestInteractAcrossProfiles'); | ||
if (result != null) return result as bool; | ||
} on PlatformException catch (e, stack) { | ||
await reportService.recordError(e, stack); | ||
} | ||
return false; | ||
} | ||
|
||
@override | ||
Future<void> switchProfile() async { | ||
try { | ||
await _platform.invokeMethod('switchProfile'); | ||
} on PlatformException catch (e, stack) { | ||
await reportService.recordError(e, stack); | ||
} | ||
return; | ||
} | ||
|
||
@override | ||
Future<String> getProfileSwitchingLabel() async { | ||
try { | ||
final result = await _platform.invokeMethod('getProfileSwitchingLabel'); | ||
return result as String; | ||
} on PlatformException catch (e, stack) { | ||
await reportService.recordError(e, stack); | ||
} | ||
return ''; | ||
} | ||
|
||
@override | ||
Future<List<String>> getTargetUserProfiles() async { | ||
try { | ||
final result = await _platform.invokeMethod('getTargetUserProfiles'); | ||
if (result != null) { | ||
return (result as List).cast<String>(); | ||
} | ||
} on PlatformException catch (e, stack) { | ||
await reportService.recordError(e, stack); | ||
} | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.