Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise RoboSuiteLauncher to launch FaceLogin instead of RoboTutor #1

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ android {

buildTypes {

debug {
buildConfigField "String", "WIFI_CONFIG", "\"DEBUG\""
debuggable true
}

release {
buildConfigField "String", "WIFI_CONFIG", "\"RELEASE\""

minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

Expand Down Expand Up @@ -68,11 +74,13 @@ android {
variant.outputs.each { output ->
def project = "RoboLaunch"
def SEP = "."
def buildType = variant.variantData.variantConfiguration.buildType.name
//def buildType = variant.variantData.variantConfiguration.buildType.name
def buildType = variant.buildType.name
def version = variant.versionName

def apkName = project + SEP + buildType + SEP + version + ".apk"
output.outputFile = new File(output.outputFile.parent, apkName)
//output.outputFile = new File(output.outputFile.parent, apkName)
output.outputFileName = apkName
}

}
Expand All @@ -81,6 +89,8 @@ android {
}

dependencies {
implementation project(path: ':comp_configuration')
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
Expand Down
49 changes: 24 additions & 25 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,71 @@

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />

<application
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:allowBackup="true"
android:clearTaskOnLaunch="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:launchMode="singleTask"
android:stateNotNeeded="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name=".HomeActivity"
android:screenOrientation="sensorLandscape"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
<activity android:name=".PermissionsActivity"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize"
android:excludeFromRecents="true"
android:lockTaskMode="if_whitelisted">

android:label="@string/app_name"
android:screenOrientation="sensorLandscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<!-- The following two intent-filters are the key to set homescreen -->
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".HomeActivity"
android:configChanges="orientation|screenSize"
android:excludeFromRecents="true"
android:label="@string/app_name"
android:launchMode="singleTask"
android:lockTaskMode="if_whitelisted"
android:screenOrientation="sensorLandscape">
</activity>
<activity
android:name=".RemoveAdmin"
android:exported="true"
android:theme="@android:style/Theme.NoDisplay"/>
android:theme="@android:style/Theme.NoDisplay" />

<receiver
android:name=".SetAppPermissions"
android:exported="true"
android:theme="@android:style/Theme.NoDisplay"/>

android:theme="@android:style/Theme.NoDisplay" />
<receiver
android:name=".StartRoboTransfer"
android:exported="true">
</receiver>

android:exported="true"/>
<receiver
android:name=".ConfigureWifi"
android:exported="true"/>

android:exported="true" />
<receiver
android:name=".AdminReceiver"
android:description="@string/app_name"
android:label="@string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">

<meta-data
android:name="android.app.device_admin"
android:resource="@xml/admin_receiver"/>
android:resource="@xml/admin_receiver" />

<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>

</application>

</manifest>
167 changes: 148 additions & 19 deletions app/src/main/java/cmu/xprize/rthomescreen/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
Expand All @@ -21,21 +23,37 @@
import android.view.ViewGroup;
import android.widget.Toast;

import com.xprize.comp_configuration.Configuration;
import com.xprize.comp_configuration.ConfigurationItems;
import com.xprize.comp_configuration.ConfigurationQuickOptions;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import java.util.Locale;

import cmu.xprize.comp_logging.CErrorManager;
import cmu.xprize.comp_logging.CInterventionLogManager;
import cmu.xprize.comp_logging.CLogManager;
import cmu.xprize.comp_logging.CPerfLogManager;
import cmu.xprize.comp_logging.CPreferenceCache;
import cmu.xprize.comp_logging.ILogManager;
import cmu.xprize.comp_logging.IPerfLogManager;
import cmu.xprize.rthomescreen.startup.CMasterContainer;
import cmu.xprize.rthomescreen.startup.CStartView;
import cmu.xprize.util.IRoboTutor;
import cmu.xprize.util.JSON_Helper;
import cmu.xprize.util.TCONST;

import static android.os.UserManager.DISALLOW_ADD_USER;
import static android.os.UserManager.DISALLOW_ADJUST_VOLUME;
import static android.os.UserManager.DISALLOW_FACTORY_RESET;
import static android.os.UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA;
import static android.os.UserManager.DISALLOW_SAFE_BOOT;
import static cmu.xprize.util.TCONST.GRAPH_MSG;

public class HomeActivity extends Activity implements IRoboTutor{
public class HomeActivity extends AppCompatActivity implements IRoboTutor{



Expand All @@ -58,15 +76,63 @@ public class HomeActivity extends Activity implements IRoboTutor{
private static final String DEBUG_TAG = "DEBUG_LAUNCH";

// do we launch FaceLogin first? Or RoboTutor?
private static final boolean LAUNCH_FACELOGIN = false;
private static final boolean LAUNCH_FACELOGIN = true;
// launch vars
public static final String STUDENT_ID_VAR = "studentId";
public static final String SESSION_ID_VAR = "sessionId";

private static ConfigurationItems configurationItems;

static public String VERSION_RT;

static public ILogManager logManager;
static public IPerfLogManager perfLogManager;

private static String hotLogPath;
private static String hotLogPathPerf;
private static String readyLogPath;
private static String readyLogPathPerf;
private static String audioLogPath;
private static String interventionLogPath;

final static public String CacheSource = TCONST.ASSETS; // assets or extern
static public String APP_PRIVATE_FILES;
static public String LOG_ID = "STARTUP";

private static final String LOG_SEQUENCE_ID = "LOG_SEQUENCE_ID";

// for devs, this is faster than changing the config file
private static final boolean QUICK_DEBUG_CONFIG = false;
private static final ConfigurationItems QUICK_DEBUG_CONFIG_OPTION = ConfigurationQuickOptions.DEBUG_EN;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

APP_PRIVATE_FILES = getApplicationContext().getExternalFilesDir("").getPath();

// Initialize the JSON Helper STATICS - just throw away the object.
//
new JSON_Helper(getAssets(), CacheSource, APP_PRIVATE_FILES);

// Gives the dev the option to override the stored config file.
configurationItems = QUICK_DEBUG_CONFIG ? QUICK_DEBUG_CONFIG_OPTION : new ConfigurationItems(); // OPEN_SOURCE opt to switch here.
Configuration.saveConfigurationItems(this, configurationItems);

// Prep the CPreferenceCache
// Update the globally accessible id object for this engine instance.
//
LOG_ID = CPreferenceCache.initLogPreference(this);
VERSION_RT = BuildConfig.VERSION_NAME;

//Start LogManager
//
initializeAndStartLogs();

//Log current config data
//
Configuration.logConfigurationItems(this);

// stuff needed for kiosk mode
// TODO move this to one class
mAdminComponentName = AdminReceiver.getComponentName(this);
Expand All @@ -76,6 +142,7 @@ protected void onCreate(Bundle savedInstanceState) {

// mKisokPackages
mKioskPackages = new ArrayList<>();
mKioskPackages.add(getPackageName());
mKioskPackages.add(flPackage);
mKioskPackages.add(rtPackage);
mKioskPackages.add(mPackageName);
Expand Down Expand Up @@ -111,11 +178,72 @@ protected void onCreate(Bundle savedInstanceState) {
Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0);
}
catch(Exception e) {

e.printStackTrace();
}
launchFtpService();
}


/**
* create log paths.
* initialize times and other IDs
* start logging
*/
private void initializeAndStartLogs() {

hotLogPath = Environment.getExternalStorageDirectory() + TCONST.HOT_LOG_FOLDER;
readyLogPath = Environment.getExternalStorageDirectory() + TCONST.READY_LOG_FOLDER;

hotLogPathPerf = Environment.getExternalStorageDirectory() + TCONST.HOT_LOG_FOLDER_PERF;
readyLogPathPerf = Environment.getExternalStorageDirectory() + TCONST.READY_LOG_FOLDER_PERF;

audioLogPath = Environment.getExternalStorageDirectory() + TCONST.AUDIO_LOG_FOLDER;

interventionLogPath = Environment.getExternalStorageDirectory() + TCONST.INTERVENTION_LOG_FOLDER;

Calendar calendar = Calendar.getInstance(Locale.US);
String initTime = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss", Locale.US).format(calendar.getTime());
String sequenceIdString = String.format(Locale.US, "%06d", getNextLogSequenceId());
// NOTE: Need to include the configuration name when that is fully merged
String logFilename = "RTSuiteHome_" + // TODO TODO TODO there should be a version name in here!!!
Configuration.configVersion(this) + "_" + BuildConfig.VERSION_NAME + "_" + sequenceIdString +
"_" + initTime + "_" + Build.SERIAL;

Log.w("LOG_DEBUG", "Beginning new session with LOG_FILENAME = " + logFilename);

logManager = CLogManager.getInstance();
logManager.transferHotLogs(hotLogPath, readyLogPath);
logManager.transferHotLogs(hotLogPathPerf, readyLogPathPerf);

logManager.startLogging(hotLogPath, logFilename);
CErrorManager.setLogManager(logManager);

perfLogManager = CPerfLogManager.getInstance();
perfLogManager.startLogging(hotLogPathPerf, "PERF_" + logFilename);

CInterventionLogManager.getInstance().startLogging(interventionLogPath,
"INT_" + logFilename);

// TODO : implement time stamps
logManager.postDateTimeStamp(GRAPH_MSG, "RTSuiteHome:SessionStart");
logManager.postEvent_I(GRAPH_MSG, "EngineVersion:" + VERSION_RT);
}

private int getNextLogSequenceId() {
SharedPreferences prefs = getPreferences(MODE_PRIVATE);

// grab the current sequence id (the one we should use for this current run
// of the app
final int logSequenceId = prefs.getInt(LOG_SEQUENCE_ID, 0);

// increase the log sequence id by 1 for the next usage
prefs.edit()
.putInt(LOG_SEQUENCE_ID, logSequenceId + 1)
.apply();

return logSequenceId;
}

/**
* launch RoboTransfer, a service to transfer log files
*/
Expand Down Expand Up @@ -238,6 +366,7 @@ public void onStartTutor() {
}

if(launchIntent != null) {
stopLockTask();
startActivity(launchIntent);
} else {
Toast.makeText(getApplicationContext(), "Please install FaceLogin", Toast.LENGTH_LONG).show();
Expand All @@ -257,24 +386,24 @@ private String generateSessionID() {
}

@Override
protected void onStart() {
super.onStart();


// start lock task mode if it's not already active
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
// ActivityManager.getLockTaskModeState api is not available in pre-M
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
if (!am.isInLockTaskMode()) {
startLockTask();
}
} else {
if (am.getLockTaskModeState() == ActivityManager.LOCK_TASK_MODE_NONE) {
startLockTask();
protected void onResume() {
super.onResume();

if (Configuration.getPinningMode(this)) {
// start lock task mode if it's not already active
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
// ActivityManager.getLockTaskModeState api is not available in pre-M
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
if (!am.isInLockTaskMode()) {
startLockTask();
}
} else {
if (am.getLockTaskModeState() == ActivityManager.LOCK_TASK_MODE_NONE) {
startLockTask();
}
}
}


setFullScreen();
}
}
Loading