robotemi / sdk

temi is an unparalleled robotic platform introducing a new dimension of development - movement. Using temi’s SDK, developers can create new functionalities and introduce new use cases via temi’s Android tablet. temi’s movement and navigation capabilities run off of it's Linux computer and uses a set of 16 sensors including a Lidar, depth cameras, driving cameras, and microphones. We encourage our developer community to suggest and request expanded functionality within the SDK and we will adhere to your needs. We want to enable you to create skills like never seen before! We will be constantly improving the SDK and its documentation. Please feel free to reach out to us with any questions or thoughts at developers@robotemi.com
https://www.robotemi.com/
209 stars 85 forks source link

Kiosk Mode issues. #234

Closed roberthobblebottom closed 3 years ago

roberthobblebottom commented 3 years ago

Why doesn't robot.setKioskModeObn(true) works when boot up my app?

        //Permissions checking and request codes
        if (ContextCompat.checkSelfPermission(requireContext(),
                Manifest.permission.READ_EXTERNAL_STORAGE) !=
                PackageManager.PERMISSION_GRANTED)
            requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE);
        else if (robot.checkSelfPermission(Permission.SETTINGS) != Permission.GRANTED) {
            robot.addOnRequestPermissionResultListener(this);
            robot.requestPermissions(
                    new ArrayList<>(Collections.singleton(Permission.SETTINGS)),
                    Permission.GRANTED
            );
        }
  Log.d(TAG, "MainFragment onCreate kioskMOde and isSelectedKioskApp Check: " + robot.isKioskModeOn() + robot.isSelectedKioskApp());
        if (!robot.isKioskModeOn() || !robot.isSelectedKioskApp()) {
            robot.setKioskModeOn(true);
            robot.requestToBeKioskApp();
            Log.d(TAG, "MainFragment onCreate kioskMOde and isSelectedKioskApp Check: " + robot.isKioskModeOn() + robot.isSelectedKioskApp());
        } //do not put as if else

Also even though I have granted Settings permission already, it also goes into the else if block as it is not granted. Also onRequestPermissionResults didn't run in my code.

It is frustrating that these codes seems glitchy.

Is there a reason why I have to access the goToSpeed and toggling of the billboard through this this kiosk permission? Why can't it be just Settings?

Is this a bug? Or some internal settings I did not configure properly?

lcgao commented 3 years ago

If you just want to request your App to be the selected Kiosk mode App, using robot.requestToBeKioskApp() is enough, but the meta-data is necessary also for that.

<meta-data
    android:name="com.robotemi.sdk.metadata.SKILL"
    android:value="@string/app_name" />

<meta-data
    android:name="com.robotemi.sdk.metadata.KIOSK"
    android:value="TRUE" />

After that, the system will pop up a dialog box after the method is called. After clicking the "Allow" button, your skill will become the currently selected Kiosk skill.

Actually onRequestPermissionResults is not the callback method of temi SDK and it belongs to Android SDK, you should implement OnRequestPermissionResultListener to listen to the permission granted status. More information for the temi permission please check the documentation and the sample code.

We want that there is only one App could modify the system settings at a time so Kiosk permission is required for that.

roberthobblebottom commented 3 years ago

hmm,

My AndroidManifest.xml have do have such xml codes already and I have already implemented OnRequestPermissionResultsListener and also the add and remove statements.

I put my codes above in MainActivity onResume, I did put in my MainFragment onCreateView before. Maybe there is something wrong with the placement here. Those codes gave me double or triple Kiosk permission requests on the very first start up of the app on temi.

I wonder if Settings permission works with ActivityResultLauncher. I used this to get the external storage permission.

Okay enough of my random thoughts and guesses, I will try to read the sample codes even though Im working with Java.

Edit: Am I right to say that when my app closes completely, KioskMode is then set to false?

roberthobblebottom commented 3 years ago

It seems to me after shifting all of the permission to onRobotReadyListener and arranging the if else blocks of each permission in a certain way but I don't understand why it will request for KioskMode twice. Any help in this regards?

 @Override
    public void onRobotReady(boolean isReady) {
        if (isReady) {
            try {
                final var activityInfo = getPackageManager()
                        .getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
                robot.onStart(activityInfo);
            } catch (PackageManager.NameNotFoundException e) {
                throw new RuntimeException(e);
            }
            robot.addOnRequestPermissionResultListener(this);
            Log.d(TAG, "MainFragment onCreate kioskMOde and isSelectedKioskApp Check: " + robot.isKioskModeOn() + robot.isSelectedKioskApp());
            Log.d(TAG, "onCreate: " + (robot.checkSelfPermission(Permission.SETTINGS) != Permission.GRANTED));
            //Permissions checking and request codes/

            if (robot.checkSelfPermission(Permission.SETTINGS) != Permission.GRANTED) {
                robot.requestPermissions(
                        new ArrayList<>(Collections.singleton(Permission.SETTINGS)),
                        Permission.GRANTED
                );
            } else if (!robot.isKioskModeOn() || !robot.isSelectedKioskApp()) {
                robot.setKioskModeOn(true);
                robot.requestToBeKioskApp();
                Log.d(TAG, "MainFragment onCreate kioskMOde and isSelectedKioskApp Check: " + robot.isKioskModeOn() + robot.isSelectedKioskApp());
            } else if (ContextCompat.checkSelfPermission(this,
                    Manifest.permission.READ_EXTERNAL_STORAGE) !=
                    PackageManager.PERMISSION_GRANTED)
                requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE);
        }
    }
roberthobblebottom commented 3 years ago

Im just going to leave this bug as it is in my code, it really can't be fixed on my part after many hours in this.

lcgao commented 3 years ago

For your questions,

  1. You will receive the robot ready event immediately when you invoke addOnRobotReadyListener(this), so consider moving addOnRobotReadyListener(this) to onCreate() for reducing invoking addOnRobotReadyListener(this) for receiving less robot ready events. Because the dialog box for requesting permission will impact the lifecycle of your Activity.

  2. No need to disable the kiosk mode if you just want to back to temi Launcher for something for a short time and you can use Robot.getInstance().startPage() instead.

roberthobblebottom commented 3 years ago

Thank you so much for 1) no more double kiosk permission request.

I could have also use 2) too but I think my stakeholders may want an actual exit function.