Skip to content
Snippets Groups Projects
Commit 5f1ed624 authored by Andrej Rasevic's avatar Andrej Rasevic
Browse files

adding new student distribution

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 591 additions and 0 deletions
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Eclipse project files
.classpath
.settings
# Proguard folder generated by Eclipse
proguard/
# Intellij project files
*.iml
*.ipr
*.iws
.idea
.idea/workspace.xml
.gradle
build/
captures/
# Mac files
.DS_Store
# Windows thumbnail db
Thumbs.db
File added
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "course.labs.permissionslab"
minSdkVersion 21
targetSdkVersion 26
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
androidTestImplementation 'com.jayway.android.robotium:robotium-solo:5.6.0'
androidTestImplementation 'com.android.support.test:rules:0.5'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
implementation 'com.android.support:support-annotations:26.0.0'
implementation 'com.android.support:support-v4:26.0.0'
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:26.0.0'
}
\ No newline at end of file
package course.labs.permissionslab.tests;
import android.content.ComponentName;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.test.ActivityInstrumentationTestCase2;
import com.robotium.solo.Solo;
import course.labs.permissionslab.ActivityLoaderActivity;
public class PermissionEnforcementTest extends
ActivityInstrumentationTestCase2<ActivityLoaderActivity> {
private Solo solo;
public PermissionEnforcementTest() {
super(ActivityLoaderActivity.class);
}
public void setUp() throws Exception {
solo = new Solo(getInstrumentation());
getActivity();
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
// Executes PermissionEnforcementTest
public void testRun() {
// =============== Section One ==================
solo.waitForActivity(
course.labs.permissionslab.ActivityLoaderActivity.class, 2000);
PackageManager pm = getActivity().getPackageManager();
try {
ActivityInfo activityInfo = pm.getActivityInfo(new ComponentName(
"course.labs.dangerousapp",
"course.labs.dangerousapp.DangerousActivity"), 0);
assertTrue(
"PermissionEnforcementTest:" +
"Section One:" +
"course.labs.permissions.DANGEROUS_ACTIVITY_PERM not enforced by DangerousActivity",
null != activityInfo && null != activityInfo.permission
&& activityInfo.permission
.equals("course.labs.permissions.DANGEROUS_ACTIVITY_PERM"));
} catch (NameNotFoundException e) {
fail("PermissionEnforcementTest:" +
"Section One:" +
"DangerousActivity not found");
}
}
}
package course.labs.permissionslab.tests;
import android.content.Context;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SdkSuppress;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.regex.Pattern;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@SdkSuppress(minSdkVersion = 21)
public class TestGoToDangerousApp {
private static final int LAUNCH_TIMEOUT = 5000;
private UiDevice mDevice;
private static final String BASIC_SAMPLE_PACKAGE
= "course.labs.permissionslab";
@Before
public void startMainActivityFromHomeScreen() {
// Initialize UiDevice instance
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
// Start from the home screen
mDevice.pressHome();
// Wait for launcher
final String launcherPackage = mDevice.getLauncherPackageName();
assertThat(launcherPackage, is(notNullValue()));
mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)),
LAUNCH_TIMEOUT);
// Launch the app
Context context = InstrumentationRegistry.getContext();
final Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE);
if (null == intent) fail();
// Clear out any previous instances
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
// Wait for the app to appear
mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)),
LAUNCH_TIMEOUT);
//click on Phone Status Activity
mDevice.findObject(By.text("PhoneStatus Activity")).click();
UiObject2 goToDangerousAppActivity = mDevice.wait(Until.findObject(By.text("Go To DangerousActivity")), 2000);
assertNotNull("Phone Status Activity Didn't start", goToDangerousAppActivity);
goToDangerousAppActivity.click();
}
@Test
public void testPermissionRequested() {
UiObject2 startDangerousApp = mDevice.wait(Until.findObject(By.text("Start Dangerous Activity")), 2000);
assertNotNull("GoToDangerousActivity Didn't start", startDangerousApp);
startDangerousApp.click();
//
UiObject2 PermissionDialog = mDevice.wait(Until.findObject(By.text("ALLOW")), 2000);
if (PermissionDialog != null)
PermissionDialog.click();
UiObject2 phoneNumber = mDevice.wait(Until.findObject(By.text("You have opened a dangerous activity")), 5000);
assertNotNull(phoneNumber);
}
}
package course.labs.permissionslab.tests;
import android.content.Context;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SdkSuppress;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;
import android.test.ActivityInstrumentationTestCase2;
import com.robotium.solo.Solo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.regex.Pattern;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@SdkSuppress(minSdkVersion = 21)
public class TestPhoneStatus{
private static final int LAUNCH_TIMEOUT = 5000;
private UiDevice mDevice;
private static final String BASIC_SAMPLE_PACKAGE
= "course.labs.permissionslab";
@Before
public void startMainActivityFromHomeScreen() {
// Initialize UiDevice instance
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
// Start from the home screen
mDevice.pressHome();
// Wait for launcher
final String launcherPackage = mDevice.getLauncherPackageName();
assertThat(launcherPackage, is(notNullValue()));
mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)),
LAUNCH_TIMEOUT);
// Launch the app
Context context = InstrumentationRegistry.getContext();
final Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE);
if (null == intent) fail();
// Clear out any previous instances
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
// Wait for the app to appear
mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)),
LAUNCH_TIMEOUT);
//click on Phone Status Activity
mDevice.findObject(By.text("PhoneStatus Activity")).click();
UiObject2 phoneStatusActivity = mDevice.wait(Until.findObject(By.text("Get Phone Number")), 2000);
assertNotNull("Phone Status Activity Didn't start", phoneStatusActivity);
phoneStatusActivity.click();
}
@Test
public void testPermissionRequested() {
UiObject2 PermissionDialog = mDevice.wait(Until.findObject(By.text("ALLOW")), 2000);
if (PermissionDialog != null)
PermissionDialog.click();
Pattern phonePattern = Pattern.compile("Phone Number: \\+?\\d+");
UiObject2 phoneNumber = mDevice.wait(Until.findObject(By.text(phonePattern)), 5000);
assertNotNull(phoneNumber);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="course.labs.permissionslab"
android:versionCode="1"
android:versionName="1.0" >
<!-- TODO add uses permission elements -->
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ActivityLoaderActivity"
android:label="@string/title_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PhoneStatusActivity"
android:label="@string/title_permissions" >
</activity>
<activity
android:name=".GoToDangerousActivity"
android:label="@string/title_activity_customization" >
</activity>
</application>
</manifest>
\ No newline at end of file
package course.labs.permissionslab;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ActivityLoaderActivity extends Activity {
private static final String TAG = "Lab-Permissions";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loader_activity);
Button startPhoneStatusButton = (Button) findViewById(R.id.start_phone_status_button);
// TODO - Add onClickListener to the startPhoneStatusButton to call startPhoneStatusActivity()
}
private void startPhoneStatusActivity() {
Log.i(TAG, "Entered startPhoneStatusActivity()");
// TODO - Start the PhoneStatusActivity
}
}
package course.labs.permissionslab;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class GoToDangerousActivity extends Activity {
private static final String TAG = "Lab-Permissions";
public final static int MY_PERMISSIONS_REQUEST_DANGEROUS_ACTIVITY = 2;
private static final String DANGEROUS_ACTIVITY_ACTION = "course.labs.permissions.DANGEROUS_ACTIVITY";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.go_to_dangerous_activity);
// TODO - Set startDangerousActivityButton value to the button with id R.id.start_dangerous_activity_button
// TODO - Add onClickListener to the startDangerousActivityButton to call startDangerousActivity()
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_DANGEROUS_ACTIVITY: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
startDangerousActivity();
} else {
Log.i(TAG, "Dangerous App won't open --- Permission was not granted");
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
private void startDangerousActivity() {
Log.i(TAG, "Entered startDangerousActivity()");
startActivity(new Intent(DANGEROUS_ACTIVITY_ACTION));
}
}
package course.labs.permissionslab;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class PhoneStatusActivity extends Activity {
private static final String TAG = "Lab-Permissions";
public final static int MY_PERMISSIONS_REQUEST_READ_PHONE_STATE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.phone_status_activity);
Button getPhoneNumButton = (Button) findViewById(R.id.get_phone_number_button);
// TODO - Add onClickListener to the getPhoneNumButton to call loadPhoneNumber()
Button goToDangerousActivityButton = (Button) findViewById(R.id.go_to_dangerous_activity_button);
// TODO - Add onClickListener to the goToDangerousActivityButton to call startGoToDangerousActivity()
}
private void loadPhoneNumber() {
TelephonyManager tMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
TextView box = (TextView) findViewById(R.id.text);
box.setText("Phone Number: "+mPhoneNumber);
Log.i(TAG, "Phone Number loaded");
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_READ_PHONE_STATE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
loadPhoneNumber();
} else {
Log.i(TAG, "Phone Number was not loaded --- Permission was not granted");
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
private void startGoToDangerousActivity() {
Log.i(TAG, "Entered startGoToDangerousActivity()");
// TODO - Start the GoToDangerousActivity
}
}
app/src/main/res/drawable-hdpi/ic_launcher.png

8.02 KiB

app/src/main/res/drawable-ldpi/ic_launcher.png

2.5 KiB

app/src/main/res/drawable-mdpi/ic_launcher.png

3.97 KiB

app/src/main/res/drawable-xhdpi/ic_launcher.png

13.2 KiB

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ActivityLoaderActivity" >
<Button
android:id="@+id/start_phone_status_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_button3" />
</LinearLayout>
\ No newline at end of file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cust_message" />
<Button
android:id="@+id/start_dangerous_activity_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cust_button1" />
</LinearLayout>
\ No newline at end of file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="250dp"
android:maxHeight="250dp"
android:text="@string/place_holder" />
<Button
android:id="@+id/get_phone_number_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/perms_button1" />
<Button
android:id="@+id/go_to_dangerous_activity_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/perms_button2" />
</LinearLayout>
\ No newline at end of file
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
\ No newline at end of file
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment