wakelocks
This commit is contained in:
parent
d6aebf45b8
commit
f5b0fba58d
7 changed files with 153 additions and 23 deletions
20
app/release/output-metadata.json
Normal file
20
app/release/output-metadata.json
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"version": 3,
|
||||||
|
"artifactType": {
|
||||||
|
"type": "APK",
|
||||||
|
"kind": "Directory"
|
||||||
|
},
|
||||||
|
"applicationId": "asgardius.page.s3manager",
|
||||||
|
"variantName": "release",
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"type": "SINGLE",
|
||||||
|
"filters": [],
|
||||||
|
"attributes": [],
|
||||||
|
"versionCode": 10,
|
||||||
|
"versionName": "0.1.8",
|
||||||
|
"outputFile": "s3-manager-0.1.8-release.apk"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"elementType": "File"
|
||||||
|
}
|
BIN
app/release/s3-manager-0.1.8-release.aab
Normal file
BIN
app/release/s3-manager-0.1.8-release.aab
Normal file
Binary file not shown.
BIN
app/release/s3-manager-0.1.8-release.apk
Normal file
BIN
app/release/s3-manager-0.1.8-release.apk
Normal file
Binary file not shown.
|
@ -7,6 +7,7 @@
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.READ_PHONE_STATE"
|
android:name="android.permission.READ_PHONE_STATE"
|
||||||
tools:node="remove" />
|
tools:node="remove" />
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
|
|
@ -10,7 +10,9 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -37,28 +39,29 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
public class Downloader extends AppCompatActivity {
|
public class Downloader extends AppCompatActivity {
|
||||||
String username, password, endpoint, bucket, filekey, filename, prefix, location, fkey;
|
String username, password, endpoint, bucket, filename, prefix, location;
|
||||||
boolean isfolder;
|
Uri fileuri;
|
||||||
int progress;
|
|
||||||
Uri fileuri, folder, uri;
|
|
||||||
EditText fprefix;
|
|
||||||
Region region;
|
Region region;
|
||||||
S3ClientOptions s3ClientOptions;
|
S3ClientOptions s3ClientOptions;
|
||||||
AWSCredentials myCredentials;
|
AWSCredentials myCredentials;
|
||||||
AmazonS3 s3client;
|
AmazonS3 s3client;
|
||||||
ProgressBar simpleProgressBar;
|
ProgressBar simpleProgressBar;
|
||||||
File dfile;
|
|
||||||
Intent intent;
|
Intent intent;
|
||||||
Button fileDownload;
|
Button fileDownload;
|
||||||
Thread downloadFile;
|
Thread downloadFile;
|
||||||
S3Object object;
|
S3Object object;
|
||||||
InputStream in;
|
private WifiManager.WifiLock mWifiLock;
|
||||||
OutputStream out;
|
private PowerManager.WakeLock mWakeLock;
|
||||||
|
private PowerManager powerManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_downloader);
|
setContentView(R.layout.activity_downloader);
|
||||||
|
// create Wifi and wake locks
|
||||||
|
mWifiLock = ((WifiManager) this.getApplicationContext().getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "Transistor:wifi_lock");
|
||||||
|
powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||||
|
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Transistor:wake_lock");
|
||||||
filename = getIntent().getStringExtra("filename");
|
filename = getIntent().getStringExtra("filename");
|
||||||
endpoint = getIntent().getStringExtra("endpoint");
|
endpoint = getIntent().getStringExtra("endpoint");
|
||||||
username = getIntent().getStringExtra("username");
|
username = getIntent().getStringExtra("username");
|
||||||
|
@ -85,6 +88,15 @@ public class Downloader extends AppCompatActivity {
|
||||||
simpleProgressBar.setVisibility(View.VISIBLE);
|
simpleProgressBar.setVisibility(View.VISIBLE);
|
||||||
fileDownload.setEnabled(false);
|
fileDownload.setEnabled(false);
|
||||||
fileDownload.setText(getResources().getString(R.string.download_in_progress));
|
fileDownload.setText(getResources().getString(R.string.download_in_progress));
|
||||||
|
//Acquiring WakeLock and WifiLock if not held
|
||||||
|
if (!mWifiLock.isHeld()) {
|
||||||
|
mWifiLock.acquire();
|
||||||
|
//System.out.println("WifiLock acquired");
|
||||||
|
}
|
||||||
|
if (!mWakeLock.isHeld()) {
|
||||||
|
mWakeLock.acquire();
|
||||||
|
//System.out.println("WakeLock acquired");
|
||||||
|
}
|
||||||
downloadFile = new Thread(new Runnable() {
|
downloadFile = new Thread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -100,6 +112,15 @@ public class Downloader extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
//simpleProgressBar.setProgress(100);
|
//simpleProgressBar.setProgress(100);
|
||||||
|
//Releasing WifiLock and WakeLock if held
|
||||||
|
if (mWifiLock.isHeld()) {
|
||||||
|
mWifiLock.release();
|
||||||
|
//System.out.println("WifiLock released");
|
||||||
|
}
|
||||||
|
if (mWakeLock.isHeld()) {
|
||||||
|
mWakeLock.release();
|
||||||
|
//System.out.println("WakeLock released");
|
||||||
|
}
|
||||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||||
fileDownload.setText(getResources().getString(R.string.download_success));
|
fileDownload.setText(getResources().getString(R.string.download_success));
|
||||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.download_success), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(),getResources().getString(R.string.download_success), Toast.LENGTH_SHORT).show();
|
||||||
|
@ -115,6 +136,15 @@ public class Downloader extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
//Releasing WifiLock and WakeLock if held
|
||||||
|
if (mWifiLock.isHeld()) {
|
||||||
|
mWifiLock.release();
|
||||||
|
//System.out.println("WifiLock released");
|
||||||
|
}
|
||||||
|
if (mWakeLock.isHeld()) {
|
||||||
|
mWakeLock.release();
|
||||||
|
//System.out.println("WakeLock released");
|
||||||
|
}
|
||||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||||
fileDownload.setText(getResources().getString(R.string.download_failed));
|
fileDownload.setText(getResources().getString(R.string.download_failed));
|
||||||
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
|
||||||
|
|
|
@ -5,10 +5,13 @@ import static android.content.ContentValues.TAG;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.os.storage.StorageManager;
|
import android.os.storage.StorageManager;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -57,11 +60,18 @@ public class Uploader extends AppCompatActivity {
|
||||||
Button fileUpload;
|
Button fileUpload;
|
||||||
Thread uploadFile;
|
Thread uploadFile;
|
||||||
private static final long MAX_SINGLE_PART_UPLOAD_BYTES = 5 * 1024 * 1024;
|
private static final long MAX_SINGLE_PART_UPLOAD_BYTES = 5 * 1024 * 1024;
|
||||||
|
private WifiManager.WifiLock mWifiLock;
|
||||||
|
private PowerManager.WakeLock mWakeLock;
|
||||||
|
private PowerManager powerManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_uploader);
|
setContentView(R.layout.activity_uploader);
|
||||||
|
// create Wifi and wake locks
|
||||||
|
mWifiLock = ((WifiManager) this.getApplicationContext().getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "Transistor:wifi_lock");
|
||||||
|
powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||||
|
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Transistor:wake_lock");
|
||||||
endpoint = getIntent().getStringExtra("endpoint");
|
endpoint = getIntent().getStringExtra("endpoint");
|
||||||
username = getIntent().getStringExtra("username");
|
username = getIntent().getStringExtra("username");
|
||||||
password = getIntent().getStringExtra("password");
|
password = getIntent().getStringExtra("password");
|
||||||
|
@ -83,11 +93,6 @@ public class Uploader extends AppCompatActivity {
|
||||||
//Toast.makeText(Uploader.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(Uploader.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
||||||
performFileSearch("Select file to upload");
|
performFileSearch("Select file to upload");
|
||||||
fprefix.setText(prefix);
|
fprefix.setText(prefix);
|
||||||
/*if (isfolder) {
|
|
||||||
folder = uploadFolder();
|
|
||||||
} else {
|
|
||||||
file = uploadFile();
|
|
||||||
}*/
|
|
||||||
fileUpload.setOnClickListener(new View.OnClickListener(){
|
fileUpload.setOnClickListener(new View.OnClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
@ -95,8 +100,15 @@ public class Uploader extends AppCompatActivity {
|
||||||
if (fileuri == null && folder == null) {
|
if (fileuri == null && folder == null) {
|
||||||
Toast.makeText(Uploader.this, getResources().getString(R.string.no_file_selected), Toast.LENGTH_SHORT).show();
|
Toast.makeText(Uploader.this, getResources().getString(R.string.no_file_selected), Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
//Toast.makeText(CreateBucket.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show();
|
//Acquiring WakeLock and WifiLock if not held
|
||||||
//System.out.println(file.getPath());
|
if (!mWifiLock.isHeld()) {
|
||||||
|
mWifiLock.acquire();
|
||||||
|
//System.out.println("WifiLock acquired");
|
||||||
|
}
|
||||||
|
if (!mWakeLock.isHeld()) {
|
||||||
|
mWakeLock.acquire();
|
||||||
|
//System.out.println("WakeLock acquired");
|
||||||
|
}
|
||||||
simpleProgressBar.setVisibility(View.VISIBLE);
|
simpleProgressBar.setVisibility(View.VISIBLE);
|
||||||
fileUpload.setEnabled(false);
|
fileUpload.setEnabled(false);
|
||||||
fileUpload.setText(getResources().getString(R.string.upload_in_progress));
|
fileUpload.setText(getResources().getString(R.string.upload_in_progress));
|
||||||
|
@ -125,6 +137,15 @@ public class Uploader extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
//Releasing WifiLock and WakeLock if held
|
||||||
|
if (mWifiLock.isHeld()) {
|
||||||
|
mWifiLock.release();
|
||||||
|
//System.out.println("WifiLock released");
|
||||||
|
}
|
||||||
|
if (mWakeLock.isHeld()) {
|
||||||
|
mWakeLock.release();
|
||||||
|
//System.out.println("WakeLock released");
|
||||||
|
}
|
||||||
//simpleProgressBar.setProgress(100);
|
//simpleProgressBar.setProgress(100);
|
||||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||||
fileUpload.setText(getResources().getString(R.string.upload_success));
|
fileUpload.setText(getResources().getString(R.string.upload_success));
|
||||||
|
@ -141,6 +162,15 @@ public class Uploader extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
//Releasing WifiLock and WakeLock if held
|
||||||
|
if (mWifiLock.isHeld()) {
|
||||||
|
mWifiLock.release();
|
||||||
|
//System.out.println("WifiLock released");
|
||||||
|
}
|
||||||
|
if (mWakeLock.isHeld()) {
|
||||||
|
mWakeLock.release();
|
||||||
|
//System.out.println("WakeLock released");
|
||||||
|
}
|
||||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||||
fileUpload.setEnabled(true);
|
fileUpload.setEnabled(true);
|
||||||
fileUpload.setText(getResources().getString(R.string.retry));
|
fileUpload.setText(getResources().getString(R.string.retry));
|
||||||
|
|
|
@ -2,7 +2,10 @@ package asgardius.page.s3manager;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -21,10 +24,9 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
|
|
||||||
// creating a variable for exoplayerview.
|
// creating a variable for exoplayerview.
|
||||||
protected StyledPlayerView playerView;
|
protected StyledPlayerView playerView;
|
||||||
|
private WifiManager.WifiLock mWifiLock;
|
||||||
|
private PowerManager.WakeLock mWakeLock;
|
||||||
// url of video which we are loading.
|
private PowerManager powerManager;
|
||||||
//String videoURL = "https://video.asgardius.company/download/videos/41780585-a935-4d53-84c8-45ce97141231-480.mp4";
|
|
||||||
|
|
||||||
ExoPlayer player;
|
ExoPlayer player;
|
||||||
|
|
||||||
|
@ -32,6 +34,10 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_video_player);
|
setContentView(R.layout.activity_video_player);
|
||||||
|
// create Wifi and wake locks
|
||||||
|
mWifiLock = ((WifiManager) this.getApplicationContext().getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "Transistor:wifi_lock");
|
||||||
|
powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||||
|
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Transistor:wake_lock");
|
||||||
//Get media url
|
//Get media url
|
||||||
String videoURL = getIntent().getStringExtra("video_url");
|
String videoURL = getIntent().getStringExtra("video_url");
|
||||||
playerView = findViewById(R.id.player_view);
|
playerView = findViewById(R.id.player_view);
|
||||||
|
@ -58,8 +64,7 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
// An HTTP error occurred.
|
// An HTTP error occurred.
|
||||||
//System.out.println("Playback error F");
|
//System.out.println("Playback error F");
|
||||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.media_conn_fail), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), getResources().getString(R.string.media_conn_fail), Toast.LENGTH_SHORT).show();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// An HTTP error occurred.
|
// An HTTP error occurred.
|
||||||
//System.out.println("Playback error F");
|
//System.out.println("Playback error F");
|
||||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.media_wrong_type), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), getResources().getString(R.string.media_wrong_type), Toast.LENGTH_SHORT).show();
|
||||||
|
@ -70,6 +75,50 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
player.addListener(new Player.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onPlaybackStateChanged(@Player.State int state) {
|
||||||
|
if (state == 3) {
|
||||||
|
// Active playback.
|
||||||
|
//Acquiring WakeLock and WifiLock if not held
|
||||||
|
if (!mWifiLock.isHeld()) {
|
||||||
|
mWifiLock.acquire();
|
||||||
|
//System.out.println("WifiLock acquired");
|
||||||
|
}
|
||||||
|
if (!mWakeLock.isHeld()) {
|
||||||
|
mWakeLock.acquire();
|
||||||
|
//System.out.println("WakeLock acquired");
|
||||||
|
}
|
||||||
|
} else if (state == 2) {
|
||||||
|
// Buffering.
|
||||||
|
//Acquiring WakeLock and WifiLock if not held
|
||||||
|
if (!mWifiLock.isHeld()) {
|
||||||
|
mWifiLock.acquire();
|
||||||
|
//System.out.println("WifiLock acquired");
|
||||||
|
}
|
||||||
|
if (!mWakeLock.isHeld()) {
|
||||||
|
mWakeLock.acquire();
|
||||||
|
//System.out.println("WakeLock acquired");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//Player inactive
|
||||||
|
//Releasing WifiLock and WakeLock if held
|
||||||
|
if (mWifiLock.isHeld()) {
|
||||||
|
mWifiLock.release();
|
||||||
|
//System.out.println("WifiLock released");
|
||||||
|
}
|
||||||
|
if (mWakeLock.isHeld()) {
|
||||||
|
mWakeLock.release();
|
||||||
|
//System.out.println("WakeLock released");
|
||||||
|
}
|
||||||
|
// Not playing because playback is paused, ended, suppressed, or the player
|
||||||
|
// is buffering, stopped or failed. Check player.getPlayWhenReady,
|
||||||
|
// player.getPlaybackState, player.getPlaybackSuppressionReason and
|
||||||
|
// player.getPlaybackError for details.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue