forked from hapjs-platform/hapjs
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hapjs-platform#631]【1300联盟版本】无障碍新增组件属性方法
Change-Id: Ib491decfcc32050c9799dd2546ed163564e602bc Signed-off-by: cmc <mingcan.chen@vivo.com>
- Loading branch information
1 parent
839910c
commit 90d388e
Showing
64 changed files
with
597 additions
and
59 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
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
94 changes: 94 additions & 0 deletions
94
core/runtime/android/runtime/src/main/java/org/hapjs/system/utils/TalkBackUtils.java
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,94 @@ | ||
/* | ||
* Copyright (C) 2022, hapjs.org. All rights reserved. | ||
*/ | ||
package org.hapjs.system.utils; | ||
|
||
import android.content.ComponentName; | ||
import android.content.Context; | ||
import android.provider.Settings; | ||
import android.text.TextUtils; | ||
import android.util.Log; | ||
|
||
import org.hapjs.runtime.ProviderManager; | ||
import org.hapjs.system.SysOpProvider; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class TalkBackUtils { | ||
private final static String TAG = "TalkBackUtils"; | ||
/* | ||
* 获取当前开启的所有辅助功能服务 | ||
*/ | ||
static int sTalkBackEnable = -1; | ||
static volatile boolean sIsForceCheck; | ||
static volatile boolean sIsChecking; | ||
static final int TALKBACK_ENABLE = 1; | ||
static final int TALKBACK_DISABLE = 0; | ||
static final int TALKBACK_DEFAULT = -1; | ||
static final char ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR = ':'; | ||
static final ComponentName TALKBACK_SERVICE_ENABLE = ComponentName.unflattenFromString("com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService"); | ||
final static TextUtils.SimpleStringSplitter sStringColonSplitter = | ||
new TextUtils.SimpleStringSplitter(ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR); | ||
|
||
private static Set<ComponentName> getEnabledServicesFromSettings(Context context) { | ||
Set<ComponentName> enabledServices = null; | ||
if (null == context) { | ||
return enabledServices; | ||
} | ||
try { | ||
String enabledServicesSetting = Settings.Secure.getString(context.getContentResolver(), "enabled_accessibility_services"); | ||
if (TextUtils.isEmpty(enabledServicesSetting)) { | ||
return Collections.emptySet(); | ||
} else { | ||
enabledServices = new HashSet(); | ||
TextUtils.SimpleStringSplitter colonSplitter = sStringColonSplitter; | ||
colonSplitter.setString(enabledServicesSetting); | ||
while (colonSplitter.hasNext()) { | ||
String componentNameString = colonSplitter.next(); | ||
ComponentName enabledService = ComponentName.unflattenFromString(componentNameString); | ||
if (enabledService != null) { | ||
enabledServices.add(enabledService); | ||
} | ||
} | ||
return enabledServices; | ||
} | ||
} catch (Exception e) { | ||
Log.w(TAG, "getEnabledServicesFromSettings error : " + e.getMessage()); | ||
} | ||
return enabledServices; | ||
} | ||
|
||
public static void setIsForceCheck(boolean isForceCheck) { | ||
TalkBackUtils.sIsForceCheck = isForceCheck; | ||
} | ||
|
||
public static boolean isEnableTalkBack(Context context, boolean forceCheck) { | ||
if (sIsChecking) { | ||
return true; | ||
} | ||
if ((sIsForceCheck || forceCheck || sTalkBackEnable == TALKBACK_DEFAULT) && null != context) { | ||
sIsForceCheck = false; | ||
sIsChecking = true; | ||
boolean isEnable = false; | ||
SysOpProvider provider = ProviderManager.getDefault().getProvider(SysOpProvider.NAME); | ||
if (null != provider) { | ||
isEnable = provider.isEnableTalkBack(context); | ||
} | ||
if (isEnable) { | ||
Set<ComponentName> componentNames = getEnabledServicesFromSettings(context); | ||
if (null != componentNames && componentNames.contains(TALKBACK_SERVICE_ENABLE)) { | ||
sTalkBackEnable = TALKBACK_ENABLE; | ||
sIsChecking = false; | ||
return true; | ||
} | ||
} | ||
sTalkBackEnable = TALKBACK_DISABLE; | ||
sIsChecking = false; | ||
return false; | ||
} else { | ||
return sTalkBackEnable == TALKBACK_ENABLE; | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.