Skip to content

Commit

Permalink
feat(permission): add request permission screen
Browse files Browse the repository at this point in the history
Signed-off-by: Rafa Hernandez <rhernandez@teclib.com>
  • Loading branch information
rafaelje authored and Hector Rondon committed Jul 13, 2018
1 parent 19c4538 commit fcce741
Show file tree
Hide file tree
Showing 7 changed files with 581 additions and 286 deletions.
177 changes: 86 additions & 91 deletions app/src/main/AndroidManifest.xml
@@ -1,100 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.flyve.inventory.agent"
android:versionName="0.5.0"
android:versionCode="1582">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.flyve.inventory.agent"
android:versionCode="1582"
android:versionName="0.5.0">

<!-- Permissions -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name='android.permission.ACCESS_COARSE_LOCATION' />
<uses-permission android:name='android.permission.ACCESS_FINE_LOCATION' />
<uses-permission android:name='android.permission.ACCESS_LOCATION_EXTRA_COMMANDS' />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- Allows unlocking your device and activating its screen so UI tests can succeed -->
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- Permissions -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- Allows unlocking your device and activating its screen so UI tests can succeed -->
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!-- Allows for storing and retrieving screenshots -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- Allows for storing and retrieving screenshots -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<!-- Allows changing locales -->
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<!-- Allows changing locales -->
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />

<application
android:label="@string/app_name"
android:name="org.flyve.inventory.agent.ui.InventoryAgentApp"
android:vmSafeMode="true"
android:theme="@style/AppTheme"
android:icon="@mipmap/ic_launcher">
<application
android:name=".ui.InventoryAgentApp"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:vmSafeMode="true">
<meta-data
android:name="com.bugsnag.android.API_KEY"
android:value="b6bc7ce0da33f92fe6c49c568af43963" />

<meta-data
android:name="com.bugsnag.android.API_KEY"
android:value="b6bc7ce0da33f92fe6c49c568af43963"/>
<activity
android:name=".ui.ActivitySplash"
android:theme="@style/NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<activity android:name=".ui.ActivitySplash"
android:theme="@style/NoActionBar">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.flyve.inventory.agent.ui.ActivityMain"
android:label="@string/app_name"
>
</activity>
<activity
android:name="org.flyve.inventory.agent.preference.InventoryParametersPreference"
android:label="@string/app_name">
</activity>
<activity
android:name="org.flyve.inventory.agent.preference.GlobalParametersPreference"
android:label="@string/app_name">
</activity>
<activity
android:name="org.flyve.inventory.agent.ui.ActivityInventoryReport"
android:label="@string/app_name"
android:launchMode="standard"
android:theme="@style/NoActionBar"
>
</activity>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.ActivityMain"
android:label="@string/app_name"></activity>
<activity
android:name=".preference.InventoryParametersPreference"
android:label="@string/app_name"></activity>
<activity
android:name=".preference.GlobalParametersPreference"
android:label="@string/app_name"></activity>
<activity
android:name=".ui.ActivityInventoryReport"
android:label="@string/app_name"
android:launchMode="standard"
android:theme="@style/NoActionBar"></activity>

<service
android:enabled="true"
android:label="Inventory Agent"
android:description="@string/agent_description"
android:icon="@mipmap/ic_launcher"
android:name="org.flyve.inventory.agent.service.InventoryService"
tools:ignore="ExportedService">
<intent-filter>
<action android:name="org.flyve.inventory.service" />
</intent-filter>
</service>
<receiver android:name="org.flyve.inventory.agent.broadcast.BootStartAgent">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name=".service.InventoryService"
android:description="@string/agent_description"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:label="Inventory Agent"
tools:ignore="ExportedService">
<intent-filter>
<action android:name="org.flyve.inventory.service" />
</intent-filter>
</service>

<receiver android:name="org.flyve.inventory.agent.broadcast.TimeAlarm">
<intent-filter>
<action android:name="org.flyve.inventory.agent.ALARM"/>
</intent-filter>
</receiver>
</application>
</manifest>
<receiver android:name=".broadcast.BootStartAgent">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:name=".broadcast.TimeAlarm">
<intent-filter>
<action android:name="org.flyve.inventory.agent.ALARM" />
</intent-filter>
</receiver>

<activity android:name=".ui.PermissionActivity"></activity>
</application>

</manifest>
@@ -0,0 +1,49 @@
/*
* Copyright Teclib. All rights reserved.
*
* Flyve MDM is a mobile device management software.
*
* Flyve MDM is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* Flyve MDM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ------------------------------------------------------------------------------
* @author Rafael Hernandez
* @copyright Copyright Teclib. All rights reserved.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/flyve-mdm/android-mdm-agent
* @link https://flyve-mdm.com
* ------------------------------------------------------------------------------
*/

package org.flyve.inventory.agent.core.permission;

import android.app.Activity;

public interface Permission {

interface View {
void showError(String message);
void permissionSuccess();
}

interface Presenter {
// Views
void showError(String message);
void permissionSuccess();

// Models
void requestPermission(Activity activity);
void openMain(Activity activity);
}

interface Model {
void requestPermission(Activity activity);
void openMain(Activity activity);
}
}
@@ -0,0 +1,68 @@
/*
* Copyright Teclib. All rights reserved.
*
* Flyve MDM is a mobile device management software.
*
* Flyve MDM is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* Flyve MDM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ------------------------------------------------------------------------------
* @author Rafael Hernandez
* @copyright Copyright Teclib. All rights reserved.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/flyve-mdm/android-mdm-agent
* @link https://flyve-mdm.com
* ------------------------------------------------------------------------------
*/

package org.flyve.inventory.agent.core.permission;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

import org.flyve.inventory.agent.ui.ActivityMain;
import org.flyve.inventory.agent.utils.Helpers;

public class PermissionModel implements Permission.Model {

private Permission.Presenter presenter;

public PermissionModel(Permission.Presenter presenter) {
this.presenter = presenter;
}

public void requestPermission(final Activity activity) {
boolean isGranted = true;
int result = ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA);
if(result != PackageManager.PERMISSION_GRANTED) {
isGranted = false;
}

result = ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE);
if(result != PackageManager.PERMISSION_GRANTED) {
isGranted = false;
}

if(!isGranted) {
ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
},
1);
}
}

@Override
public void openMain(Activity activity) {
Helpers.openActivity(activity, ActivityMain.class, true);
}
}
@@ -0,0 +1,63 @@
/*
* Copyright Teclib. All rights reserved.
*
* Flyve MDM is a mobile device management software.
*
* Flyve MDM is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* Flyve MDM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ------------------------------------------------------------------------------
* @author Rafael Hernandez
* @copyright Copyright Teclib. All rights reserved.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/flyve-mdm/android-mdm-agent
* @link https://flyve-mdm.com
* ------------------------------------------------------------------------------
*/

package org.flyve.inventory.agent.core.permission;

import android.app.Activity;

public class PermissionPresenter implements Permission.Presenter {

private Permission.View view;
private Permission.Model model;

public PermissionPresenter(Permission.View view){
this.view = view;
model = new PermissionModel(this);
}

@Override
public void showError(String message) {
if(view!=null) {
view.showError(message);
}
}

@Override
public void permissionSuccess() {
if(view!=null) {
view.permissionSuccess();
}
}

@Override
public void requestPermission(Activity activity) {
model.requestPermission(activity);
}

@Override
public void openMain(Activity activity) {
model.openMain(activity);
}


}

0 comments on commit fcce741

Please sign in to comment.