Skip to main content

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​

  1. 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);
}
  • PrivacyChecker callback PrivacyCallback and PrivacyResult are defined as follows, parameters:

    1. methodName is the passed methodName;

    2. passed indicates whether the inspection has passed;

    3. errorNo and errorMessage will 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 PrivacyChecker via TJGameHandle.
private TJHostHandle hostHandle;
hostHandle.setPrivacyChecker(new RandomPrivacyChecker());
Information TypemethodNameDescription
MicrophonestartRecorderManagerRecorderManager.start
CamerastartCameraManagertj.createCamera
BluetoothopenBluetoothAdapter, createBLEPeripheralServertj.openBluetoothAdapter, tj.createBLEPeripheralServer
Gyroscope SensorstartGyroscopetj.startGyroscope
Direction SensorstartDeviceMotionListeningtj.startDeviceMotionListening
Magnetic Field SensorstartCompasstj.startCompass
Acceleration SensorstartAccelerometertj.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);
}
}
}