Privacy Management
1 Privacy Permission Check
See Host Privacy Policy Access for details
Interface Prototype
void setPrivacyChecker(PrivacyChecker checker)
2 Host Privacy Policy Access
Function Introduction
To standardize the behavior of developers when invoking system capabilities, such as camera, Bluetooth, sensors, etc., the host provides an asynchronous call interface for permission checking to third-party access platforms. Third-party platforms can check or guide users to grant relevant permissions through this interface.
Access Instructions
- Implement the `PrivacyChecker` interface, where the possible values of `methodName` are described in the next section Related APIs section
public interface PrivacyChecker {
void requirePrivacy(String methodName, PrivacyCallback callback);
}
-
PrivacyCheckercallbackPrivacyCallbackandPrivacyResultare defined as follows, parameters:-
methodNameis the passedmethodName; -
passedindicates whether the inspection has passed; -
errorNoanderrorMessagewill be returned to the relevant call in the js.
-
public interface PrivacyCallback {
void onPrivacyResult(String methodName, PrivacyResult privacyResult);
}
public class PrivacyResult {
private boolean passed;
private int errorNo;
private String errorMessage;
public PrivacyResult(boolean passed, int errNo, String errMsg) {
this.passed = passed;
this.errorNo = errNo;
this.errorMessage = errMsg;
}
public boolean isPassed() {
return passed;
}
public void setPassed(boolean passed) {
this.passed = passed;
}
public int getErrorNo() {
return errorNo;
}
public void setErrorNo(int errorNo) {
this.errorNo = errorNo;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
}
- Pass in a custom
PrivacyCheckerviaTJGameHandle.
private TJHostHandle hostHandle;
hostHandle.setPrivacyChecker(new RandomPrivacyChecker());
3 Related APIs
| Information Type | methodName | Description |
|---|---|---|
| Microphone | startRecorderManager | RecorderManager.start |
| Camera | startCameraManager | tj.createCamera |
| Bluetooth | openBluetoothAdapter, createBLEPeripheralServer | tj.openBluetoothAdapter, tj.createBLEPeripheralServer |
| Gyroscope Sensor | startGyroscope | tj.startGyroscope |
| Direction Sensor | startDeviceMotionListening | tj.startDeviceMotionListening |
| Magnetic Field Sensor | startCompass | tj.startCompass |
| Acceleration Sensor | startAccelerometer | tj.startAccelerometer |
4 Example
A PrivacyChecker that returns random results.
public class RandomPrivacyChecker implements PrivacyChecker {
private static final String TAG = "RandomPrivacyChecker";
private PrivacyResult randomResult() {
int random = (int) (Math.random() * 10);
if (random < 5) {
return new PrivacyResult(true, 0, "privacy granted");
} else {
return new PrivacyResult(false, 1, "privacy denied");
}
}
@Override
public void requirePrivacy(String methodName, PrivacyCallback callback) {
try {
Thread.sleep(500); // simulate time-consuming operations
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (callback != null) {
PrivacyResult result = randomResult();
Log.d(TAG, "requirePrivacy: " + methodName + " " + result.getErrorMessage());
callback.onPrivacyResult(methodName, result);
}
}
}