Completely useless android brute force unlocker - General Topics

So, I took the time to write (poorly) a program to brute force an android bootloader password. I was bored. It would take years, but if you feel like not being able to use your phone for that long, or maybe you want to use it in something else or improve it, here it is:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
/*----------------------------------------------------------------*/
/* Broot-force: An android brute-force boorloader unlocker */
/* By Jonathan Schuett */
/* You download or use this software at your own risk, and the */
/* creator assumes no liability for damage, failure, unexpected */
/* outcomes, boogeymen, or timey-wimey nonsense. Your usage of */
/* this software is to be interpreted as an acceptance of these */
/* terms. You may freely distribute, modify, or reuse this code */
/* or any part herein, as long as you state that you've done so */
/*----------------------------------------------------------------*/
int success = 1;
int recurse = 1;
char update(char sign)
{
recurse=1;
if(sign=='Z') {
sign='0';
recurse=0;
return(sign);
}
if(sign=='Y')
sign='Z';
if(sign=='X')
sign='Y';
if(sign=='W')
sign='X';
if(sign=='V')
sign='W';
if(sign=='U')
sign='V';
if(sign=='T')
sign='U';
if(sign=='S')
sign='T';
if(sign=='R')
sign='S';
if(sign=='Q')
sign='R';
if(sign=='P')
sign='Q';
if(sign=='O')
sign='P';
if(sign=='N')
sign='O';
if(sign=='M')
sign='N';
if(sign=='L')
sign='M';
if(sign=='K')
sign='L';
if(sign=='J')
sign='K';
if(sign=='I')
sign='J';
if(sign=='H')
sign='I';
if(sign=='G')
sign='H';
if(sign=='F')
sign='G';
if(sign=='E')
sign='F';
if(sign=='D')
sign='E';
if(sign=='C')
sign='D';
if(sign=='B')
sign='C';
if(sign=='A')
sign='B';
if(sign=='9')
sign='A';
if(sign=='8')
sign='9';
if(sign=='7')
sign='8';
if(sign=='6')
sign='7';
if(sign=='5')
sign='6';
if(sign=='4')
sign='5';
if(sign=='3')
sign='4';
if(sign=='2')
sign='3';
if(sign=='1')
sign='2';
if(sign=='0')
sign='1';
return(sign);
}
/*
char update(char sign)
{
sign = ++sign % 'F';
if(sign == '9' + 1)
sign = 'A';
if(sign == 'F')
recurse = 0;
return sign;
}
*/
void main(void)
{
char bt1, bt2, bt3, bt4, bt5, bt6, bt7, bt8, bt9, bt10, bt11, bt12, bt13, bt14, bt15, bt16;
bt1 = bt2 = bt3 = bt4 = bt5 = bt6 = bt7 = bt8 = bt9 = bt10 = bt11 = bt12 = bt13 = bt14 = bt15 = bt16 = '0';
char attempt[37];
printf("Sequential number generator for brute forcing android bootloaders. Version 0.05\n");
getchar();
while(success==1)
{
getchar();
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
while(success==1&&recurse==1)
{
char attempt[37] = {'f', 'a', 's', 't', 'b', 'o', 'o', 't', ' ', 'o', 'e', 'm', ' ', 'u', 'n', 'l', 'o', 'c', 'k', ' ', bt1, bt2, bt3, bt4, bt5, bt6, bt7, bt8, bt9, bt10, bt11, bt12, bt13, bt14, bt15, bt16, '\0' };
system(attempt);
bt16 = update(bt16);
}
bt15 = update(bt15);
}
bt14 = update(bt14);
}
bt13 = update(bt13);
}
bt12 = update(bt12);
}
bt11 = update(bt11);
}
bt10 = update(bt10);
}
bt9 = update(bt9);
}
bt8 = update(bt8);
}
bt7 = update(bt7);
}
bt6 = update(bt6);
}
bt5 =update(bt5);
}
bt4 = update(bt4);
}
bt3 = update(bt3);
}
bt2 = update(bt2);
}
if(bt1!='Z')
{
bt1 = update(bt1);
} else if(bt1=='Z') {
printf("\n\n\nAll 16 character RSA strings attempted. If your device is unlocked and you're seeing this, notify the author, as the detection function has failed. If your device is not unlocked, notify the author in the forum thread you downloaded this from. Please include your device model, and the version of this script attempted.");
}
}
}

Related

source code of StartMenuRebuilder (small stuff for A.I.)

Finally,I have successfully get my PC online,before today only one computer - my friend's PC can online,the lessor of house only provided a port and bind MAC address.
Code:
/*
Author:xiaojin1985[小金]
Version:1.2
Updates:
+ Directories can be removed now.
*/
// StartMenuRebuilder.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
BOOL IsFileExist(LPCTSTR lpFileName){
WIN32_FIND_DATA m_data;
HANDLE hFile;
BOOL bFileFound = FALSE;
hFile=FindFirstFile(lpFileName,&m_data);
if(hFile==INVALID_HANDLE_VALUE){
bFileFound = FALSE;
}else{
bFileFound = TRUE;
}
FindClose(hFile);
return bFileFound;
}
BOOL SearchDir(PCTSTR ptzSrc)
{
WIN32_FIND_DATA fd;
TCHAR tzSrc[MAX_PATH];
TCHAR tzFind[MAX_PATH];
wsprintf(tzFind, TEXT("%s\\*"), ptzSrc);
HANDLE hFind = FindFirstFile(tzFind, &fd);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (fd.cFileName[0] != '.')
{
wsprintf(tzSrc, TEXT("%s\\%s"), ptzSrc, fd.cFileName);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
SearchDir(tzSrc);
}
else
{
//_debug(L"%s",tzSrc);
SetFileAttributes(tzSrc,FILE_ATTRIBUTE_NORMAL);
DeleteFile(tzSrc);
}
}
}
while (FindNextFile(hFind, &fd));
FindClose(hFind);
RemoveDirectory(ptzSrc);
}
return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR szPath[MAX_PATH];
wchar_t szFileExec[256] = _T("");
wchar_t WorkPath[255];//工作路径
int i;
GetModuleFileName(NULL,WorkPath,255);
i = wcslen(WorkPath)-1;
for(;WorkPath[i]!='\\';i--);
WorkPath[i+1]='\0';
wsprintf(szFileExec,TEXT("%sStartMenu.cab"),WorkPath);
if(IsFileExist(szFileExec)){
SHGetSpecialFolderPath(NULL, szPath, CSIDL_STARTMENU, FALSE);
SearchDir(szPath);
//If you want run it independence,plz remove the comment lines.
/*
PROCESS_INFORMATION pi;
STARTUPINFO si;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
wchar_t szFileArgv[256] = _T("");
wsprintf(szFileArgv,TEXT("/nodelete /noui /silent %s"),szFileExec);
//_debug(L"%s",szFileArgv);
CreateProcess(TEXT("wceload.exe"),szFileArgv,0,0,0,0,0,0,&si,&pi);
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);*/
}else{
MessageBox(NULL,L"StartMenu.cab NOT FOUND!",L"Rebuilder by xiaojin",MB_OK);
}
return 0;
}
ha ha ha ha ha ha
source code of StartMenuRebuilder (small stuff for A.I.)
You're talking about something?

Android - FritzBox VPN

Hello,
i would like to connect my desire with vpn to my fritzxbox.
can someone help me?
what do i have to choose?
L2TP-VPN
L2TP/IPSec PSK-VPN
L2TP/IPSec CRT-VPN
i have this two files vpnuser.cfg and vpnuser.vpn
there should be all necessitate data but don't know what to take.
cpnuser.vpn
Code:
n:version:3
n:network-ike-port:500
n:network-mtu-size:1380
n:client-addr-auto:1
n:network-natt-port:4500
n:network-natt-rate:15
n:network-frag-size:540
n:network-dpd-enable:1
n:client-banner-enable:1
n:network-notify-enable:1
n:client-dns-used:0
n:client-dns-auto:1
n:client-dns-suffix-auto:1
n:client-splitdns-used:1
n:client-splitdns-auto:0
n:client-wins-used:0
n:client-wins-auto:1
n:phase1-dhgroup:2
n:phase1-keylen:256
n:phase1-life-secs:86400
n:phase1-life-kbytes:0
n:vendor-chkpt-enable:0
n:phase2-keylen:256
n:phase2-life-secs:3600
n:phase2-life-kbytes:0
n:policy-nailed:0
n:policy-list-auto:0
s:network-host:dyndns
s:client-auto-mode:pull
s:client-iface:virtual
s:network-natt-mode:enable
s:network-frag-mode:enable
s:auth-method:mutual-psk
s:ident-client-type:ufqdn
s:ident-server-type:address
s:ident-client-data:myusername
b:auth-mutual-psk:long_code
s:phase1-exchange:aggressive
s:phase1-cipher:aes
s:phase1-hash:sha1
s:phase2-transform:esp-aes
s:phase2-hmac:sha1
s:ipcomp-transform:deflate
n:phase2-pfsgroup:2
s:policy-list-include:192.168.178.0 / 255.255.255.0
vpnuser.cfg
Code:
/*
* C:\Users\myname\AppData\Roaming\AVM\FRITZ!Fernzugang\dyndns\user\vpnuser.cfg
* Tue Feb 16 11:18:33 2010
*/
version {
revision = "$Revision: 1.30 $";
creatversion = "1.1";
}
pwcheck {
}
datapipecfg {
security = dpsec_quiet;
icmp {
ignore_echo_requests = no;
destunreach_rate {
burstfactor = 6;
timeout = 1;
}
timeexceeded_rate {
burstfactor = 6;
timeout = 1;
}
echoreply_rate {
burstfactor = 6;
timeout = 1;
}
}
masqtimeouts {
tcp = 15m;
tcp_fin = 2m;
tcp_rst = 3s;
udp = 5m;
icmp = 30s;
got_icmp_error = 15s;
any = 5m;
tcp_connect = 6m;
tcp_listen = 2m;
}
ipfwlow {
input {
}
output {
}
}
ipfwhigh {
input {
}
output {
}
}
NAT_T_keepalive_interval = 20;
}
targets {
policies {
name = "mydyn.dns";
connect_on_channelup = no;
always_renew = no;
reject_not_encrypted = no;
dont_filter_netbios = yes;
localip = 0.0.0.0;
virtualip = 192.168.178.201;
remoteip = 0.0.0.0;
remotehostname = "mydyn.dns";
localid {
user_fqdn = "username";
}
mode = mode_aggressive;
phase1ss = "all/all/all";
keytype = keytype_pre_shared;
key = "long code";
cert_do_server_auth = no;
use_nat_t = yes;
use_xauth = no;
use_cfgmode = no;
phase2localid {
ipaddr = 192.168.178.201;
}
phase2remoteid {
ipnet {
ipaddr = 192.168.178.0;
mask = 255.255.255.0;
}
}
phase2ss = "esp-all-all/ah-none/comp-all/pfs";
accesslist = "permit ip any 192.168.178.0 255.255.255.0";
wakeupremote = no;
}
}
policybindings {
}
// EOF
can someone help me? thanks in advance
..any updates on this ?
I'm facing the same problem
,Wolfgang
never seen anything like that
this may help you
show post#775248 there is a solution for vpnc and fritzbox
mp1405 said:
show post#775248 there is a solution for vpnc and fritzbox
Click to expand...
Click to collapse
Where is this post#775248?
Hello there,
1. It is necessary that your device is rooted.
2. In order to connect via Fritz!VPN you need to use VPNC Widget. If "check prerequisites" states that it should work you are good to go.
3. The config file for FritzBox needs to look like this in order to work with Android devices. You need to change the UPPERCASE values *and IF changed from the 192.168.178.X default also change IP settings* afterwards enter these values in VPNC Widget and it should work.
/*
/*
*C:\Users\tom\AppData\Roaming\AVM\FRITZ!Fernzugang\fritzbox_avmvpn_dyndns_org.cfg
* Mon Mar 07 17:49:59 2011
*/
vpncfg {
connections {
enabled = yes;
conn_type = conntype_user;
name = "NAMEINFRITZGUI";
always_renew = no;
reject_not_encrypted = no;
dont_filter_netbios = yes;
localip = 0.0.0.0;
local_virtualip = 0.0.0.0;
remoteip = 0.0.0.0;
remote_virtualip = 192.168.100.201;
remoteid {
key_id = "USER";
}
mode = phase1_mode_aggressive;
phase1ss = "all/all/all";
keytype = connkeytype_pre_shared;
key = "PASSWORD";
cert_do_server_auth = no;
use_nat_t = yes;
use_xauth = yes;
use_cfgmode = no;
xauth {
valid = yes;
username = "USER1";
passwd = "PASSWORT1";
}
phase2localid {
ipnet {
ipaddr = 0.0.0.0;
mask = 0.0.0.0;
}
}
phase2remoteid {
ipaddr = 192.168.100.201;
}
phase2ss = "esp-all-all/ah-none/comp-all/no-pfs";
accesslist = "permit ip 0.0.0.0 0.0.0.0 192.168.100.201 255.255.255.255";
}
ike_forward_rules = "udp 0.0.0.0:500 0.0.0.0:500",
"udp 0.0.0.0:4500 0.0.0.0:4500";
}
// EOF
Click to expand...
Click to collapse
Greetings
Geniac
@geniac
Thank you
Hello all ...
I'd like to connect my HTC1s via VPN to my Fritzbox 3170.
The connection works, I have access to my homenetwork and a small bandwidth to check my emails, but when I start the browser or speedtest there's no connection.
I use cm9 alpha14 and I tried VPNC Widget and vpncilla as well as onboard vpn.
Do I have to make further modifications to my Fritzbox?
for the cfg - file I used the code posted by geniac
thanks 4 ur help
greetz
Tomcatz

[Q] HELP! HELP!why my backround app can't work!

i has decompile screen_capture_1.03 and i saw these code:
hookThread = new BackgroundWorker();
hookThread.DoWork += delegate (object o, DoWorkEventArgs e) {
while (true)
{
for (int j = 0; j < m_listenFor.Length; j++)
{
if ((DllImportCaller.lib.GetAsyncKeyState7(m_listenFor[j]) != 0) && (OnKeyDown != null))
{
OnKeyDown(null, (PhysicalKeys) m_listenFor[j]);
}
}
Thread.Sleep(500);
}
};
hookThread.RunWorkerAsync();
/////////////////////////////
so i use it and change it to a test code:
BackgroundWorker s=new BackgroundWorker();
S.DoWork+=delegate(object o,DoWorkEventArgs e)
{
while(true)
{
MessageBox.Show(i.ToString());//varible i has been declared before;
i++;
Thread.Sleep(500);
}
};
s.RunWorkAsync();
!!however,we i run it on my hdc device!nothing happened!WHY? AND
I have changed the DehydrateOnPause from 3 to 0.but it still can't work !
who can save me!!!!!!
kissmegodlike said:
i has decompile screen_capture_1.03 and i saw these code:
hookThread = new BackgroundWorker();
hookThread.DoWork += delegate (object o, DoWorkEventArgs e) {
while (true)
{
for (int j = 0; j < m_listenFor.Length; j++)
{
if ((DllImportCaller.lib.GetAsyncKeyState7(m_listenFor[j]) != 0) && (OnKeyDown != null))
{
OnKeyDown(null, (PhysicalKeys) m_listenFor[j]);
}
}
Thread.Sleep(500);
}
};
hookThread.RunWorkerAsync();
/////////////////////////////
so i use it and change it to a test code:
BackgroundWorker s=new BackgroundWorker();
S.DoWork+=delegate(object o,DoWorkEventArgs e)
{
while(true)
{
MessageBox.Show(i.ToString());//varible i has been declared before;
i++;
Thread.Sleep(500);
}
};
s.RunWorkAsync();
!!however,we i run it on my hdc device!nothing happened!WHY? AND
I have changed the DehydrateOnPause from 3 to 0.but it still can't work !
who can save me!!!!!!
Click to expand...
Click to collapse
You have to keep the for int in there, as it is constantly waiting for you to press the button.
TheMrBlue said:
You have to keep the for int in there, as it is constantly waiting for you to press the button.
Click to expand...
Click to collapse
In fact,i mean the backroundworker does't work at all.cound you tell me what errors result in my code's failure.

Making OC module help!!

I build source like this
/*
* OC Module By Useby
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/cpufreq.h>
// defines
#define KHZ_T1000
#define APLL_GEN_CLK532*1000//khz
#define OFS_KALLSYMS_LOOKUP_NAME0xc0251e8c// kallsyms_lookup_name
unsigned int S5P6442_FREQ_TAB = 0;
static struct cpufreq_policy *policy;
/* frequency */
static struct cpufreq_frequency_table s5p6442_freq_table[] = {
{APLL_GEN_CLK, APLL_GEN_CLK},
{APLL_GEN_CLK, APLL_GEN_CLK/2},
{APLL_GEN_CLK, APLL_GEN_CLK/4},
{0, CPUFREQ_TABLE_END},
};
static struct cpufreq_frequency_table freq_table_666_166MHz[] = {
{0, 667*KHZ_T},
{1, (667*KHZ_T)/2},
{2, (667*KHZ_T)/3},
{3, (667*KHZ_T)/4},
#ifdef SYSCLK_CHANGE
#ifdef USE_DVFS_AL1_LEVEL
{4, (667*KHZ_T)/4},
{5, (667*KHZ_T)/8},
{6, CPUFREQ_TABLE_END},
#else /* USE_DVFS_AL1_LEVEL */
{4, (667*KHZ_T)/8},
{5, CPUFREQ_TABLE_END},
#endif /* USE_DVFS_AL1_LEVEL */
#else /* SYSCLK_CHANGE */
{4, CPUFREQ_TABLE_END},
#endif /* SYSCLK_CHANGE */
};
struct cpufreq_frequency_table *freq_tab = s5p6442_freq_table;
// external variables / functions
typedef unsigned long (*kallsyms_lookup_name_type)(const char *name);
static kallsyms_lookup_name_type kallsyms_lookup_name_dx;
// init module
static int __init useby_oc_init(void)
{
printk(KERN_INFO MODULE_NAME ": module " MODULE_VER " loaded.\n");
freq_tab[4].frequency = 867000;
policy->cpuinfo.max_freq = 867000;
policy->max = 867000;
printk(KERN_INFO MODULE_NAME ": overclocking applied.\n");
return 0;
}
// exit module - will most likely not be called
static void __exit useby_oc_exit(void)
{
printk(KERN_INFO MODULE_NAME ": OC module unloaded\n");
}
module_init(useby_oc_init);
module_exit(useby_oc_exit);
MODULE_LICENSE("GPL");
I'm noop at C language so there's an error when i use the module my phone would freeze!! can anybody help me??(I Built this module using Kallsyms_lookup_name function in X8 undervolt and i'm going to use this later)

Need help recompiling settings.apk

I have a modified wifidisplaysettings.java file that enables auto connect to wifi display but i need some help getting it into settings.apk. can anyone help with recompiling?
How did you decompile?
Sent from my Nexus 5 using Tapatalk
i used apk2java. i was also talking to someone on another forum who gave me the modified java file but said that the files I got from decompiling may not be useable for recompiling, so im not really sure how to get this back in to there.
I would recommend decompiling with apk tool, making the mods then recompiling with Apk tool. There are guides on xda
Sent from my Nexus 5 using Tapatalk
i decompiled with apk tool but i got smali files. i dont know how to make the changes i need in smali. the modified file i have is a java file.
Munkee915 said:
ii dont know how to make the changes i need in smali
Click to expand...
Click to collapse
If you're wanting to recompile, you'll need to work that out
Sent from my Nexus 5 using Tapatalk
well here are the steps ive taken so far. Keep in mind im not a programmer. Im doing everything from the seat of my pants and whatever i can find on here and google:
1. I have the modified wifidisplaysettings.java and settings.apk from the original author (JOK on appradio forums, he gave me permission to seek help compiling into something i can use) which is built off of CM 10.2 settings.apk.
2. Tried flashing his file, flash failed
3. Tried modifying his zip file with the META-INF from another mod i have on the phone. flash succeeds, but Settings is missing from my apps. i can see it in system/priv-app but when i click on it it asks to install and then fails.
4. I decompiled my settings.apk (stock kot49h) to java and changed my wifidisplaysettings.java w/ his edits but im told i cant recompile this back to a usable APK.
5. I decompiled his settings.apk and my settings.apk to smali and moved his wfd folder into my decompiled folder, recompiled my settings.apk, signed and flashed to my phone. Phone boots but again Settings is missing from my apps
6. Tried flashing CM 11 nightly and then flashing his settings file, no dice
7. Pulled the stock CM 11 settings.apk, decompiled to smali and swapped the wfd folder, recompiled, signed and flashed. i can open settings now but when i go to cast screen settings crashes.
8. Restored my nandroid backup and now im seeking help
When you recompile, don't forget to replace all the signature files from your original apk.
http://forum.xda-developers.com/showthread.php?t=1989533
Sent from my Nexus 5 using Tapatalk
is that not the same thing as resigning the apk? I've been using signapk for that part and then going to flash after that.
Rule it out
Sent from my Nexus 5 using Tapatalk
rootSU said:
Rule it out
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
Same thing. Compiled and pulled the xml files and resources file and put them into the original apk and flashed. Phone boots but settings is nowhere to be found.
Munkee915 said:
Same thing. Compiled and pulled the xml files and resources file and put them into the original apk and flashed. Phone boots but settings is nowhere to be found.
Click to expand...
Click to collapse
You need to decompile and recompile with apktool or any other tool like that mate. You need to edit the smali if you want to make changes. But if i am not wrong you can decompile the settingsprovider and make the changes in bools to enable that option.
Sent from my Nexus 5 using XDA Premium 4 mobile app
maybe (or definitely) i dont understand what im doing. i am decompiling and compiling with apktool. when i decompile i see smali files and i make the changes there. i then recompile with apktool and in the resulting apk i only have xml files, so going with guide rootSU pointed me to i use winrar and pull them from teh new apk and drop them in the original apk along with resources.arsc and flash that. the original author has suggested i build the entire image again from source using his java file and it should work, but taht would mean i have to setup a build environment. i cant even get this right im not sure i can build an image from source lol.
Sometimes it's the modifications that cause the problem.
Is his settings.apk from the same phone? Same ROM? You can't build stock settings from source. Only aosp.
Sent from my Nexus 5 using Tapatalk
his mod was done on CM 10.2 on a GS4. Not the same but when we compared the source they were almost identical so we were hoping it was close enough that they would translate over.
Very doubtful
Sent from my Nexus 5 using Tapatalk
Well that's disappointing. It seems like a really useful mod that a lot of people ask for it's a shame we cant get it going. if anyone wants to take a crack at it here is the java code I was given. Hopefully someone can get this done.
Code:
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.wfd;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.hardware.display.DisplayManager;
import android.hardware.display.IRemoteDisplayAdapter;
import android.hardware.display.WifiDisplay;
import android.hardware.display.WifiDisplayStatus;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.text.Html;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;
import com.android.settings.ProgressCategory;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
/**
* The Settings screen for WifiDisplay configuration and connection management.
*/
public final class WifiDisplaySettings extends SettingsPreferenceFragment {
private static final String TAG = "WifiDisplaySettings";
private static final int MENU_ID_SCAN = Menu.FIRST;
private DisplayManager mDisplayManager;
private boolean mWifiDisplayOnSetting;
private WifiDisplayStatus mWifiDisplayStatus;
private WifiDisplayStatus mRemoteDisplayStatus;
private IRemoteDisplayAdapter mRemoteDisplayAdapter;
private PreferenceGroup mPairedDevicesCategory;
private ProgressCategory mAvailableDevicesCategory;
private TextView mEmptyView;
private Switch mActionBarSwitch;
private CheckBoxPreference mDisableHDCP;
private static final String DISABLE_HDCP_PREF = "persist.sys.wfd.nohdcp";
public WifiDisplaySettings() {
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mDisplayManager = (DisplayManager)getActivity().getSystemService(Context.DISPLAY_SERVICE);
mRemoteDisplayAdapter = mDisplayManager.getRemoteDisplayAdapter();
addPreferencesFromResource(R.xml.wifi_display_settings);
setHasOptionsMenu(true);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Activity activity = getActivity();
mActionBarSwitch = new Switch(activity);
mActionBarSwitch.setOnCheckedChangeListener(mSwitchOnCheckedChangedListener​);
final int padding = activity.getResources().getDimensionPixelSize(
R.dimen.action_bar_switch_padding);
mActionBarSwitch.setPaddingRelative(0, 0, padding, 0);
activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM);
activity.getActionBar().setCustomView(mActionBarSwitch,
new ActionBar.LayoutParams(
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_VERTICAL | Gravity.END));
mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
getListView().setEmptyView(mEmptyView);
update();
// JOK auto connect
autoConnect();
if (mWifiDisplayStatus.getFeatureState() == WifiDisplayStatus.FEATURE_STATE_UNAVAILABLE) {
activity.finish();
}
}
@Override
public void onDestroyView() {
getActivity().getActionBar().setCustomView(null);
super.onDestroyView();
}
private void scanRemoteDisplays() {
try {
mRemoteDisplayAdapter.scanRemoteDisplays();
}
catch (RemoteException e) {
}
}
@Override
public void onResume() {
super.onResume();
Context context = getActivity();
IntentFilter filter = new IntentFilter();
filter.addAction(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED);
filter.addAction(DisplayManager.ACTION_REMOTE_DISPLAY_STATUS_CHANGED);
context.registerReceiver(mReceiver, filter);
getContentResolver().registerContentObserver(Settings.Secure.getUriFor(
Settings.Global.WIFI_DISPLAY_ON), false, mSettingsObserver);
mDisplayManager.scanWifiDisplays();
scanRemoteDisplays();
update();
// JOK auto connect
autoConnect();
}
@Override
public void onPause() {
super.onPause();
Context context = getActivity();
context.unregisterReceiver(mReceiver);
getContentResolver().unregisterContentObserver(mSettingsObserver);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuItem item = menu.add(Menu.NONE, MENU_ID_SCAN, 0,
mWifiDisplayStatus.getScanState() == WifiDisplayStatus.SCAN_STATE_SCANNING ?
R.string.wifi_display_searching_for_devices :
R.string.wifi_display_search_for_devices);
item.setEnabled(mWifiDisplayStatus.getFeatureState() == WifiDisplayStatus.FEATURE_STATE_ON
&& mWifiDisplayStatus.getScanState() == WifiDisplayStatus.SCAN_STATE_NOT_SCANNING);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_ID_SCAN:
if (mWifiDisplayStatus.getFeatureState() == WifiDisplayStatus.FEATURE_STATE_ON) {
mDisplayManager.scanWifiDisplays();
}
if (mRemoteDisplayStatus.getFeatureState() == WifiDisplayStatus.FEATURE_STATE_ON) {
scanRemoteDisplays();
}
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
if (preference instanceof WifiDisplayPreference) {
WifiDisplayPreference p = (WifiDisplayPreference)preference;
WifiDisplay display = p.getDisplay();
boolean isActive = false;
if (p.isRemoteDisplay()) {
isActive = display.equals(mRemoteDisplayStatus.getActiveDisplay());
} else {
isActive = display.equals(mWifiDisplayStatus.getActiveDisplay());
}
if (isActive) {
showDisconnectDialog(display, p.isRemoteDisplay());
} else if (!p.isRemoteDisplay()) {
mDisplayManager.connectWifiDisplay(display.getDeviceAddress());
} else {
try {
mRemoteDisplayAdapter.connectRemoteDisplay(display.getDeviceAddress());
}
catch (RemoteException e) {
}
}
}
else if (preference == mDisableHDCP) {
SystemProperties.set(DISABLE_HDCP_PREF, mDisableHDCP.isChecked() ? "1" : "0");
return true;
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
private void update() {
mWifiDisplayOnSetting = Settings.Global.getInt(getContentResolver(),
Settings.Global.WIFI_DISPLAY_ON, 0) != 0;
mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus();
try {
mRemoteDisplayStatus = mRemoteDisplayAdapter.getRemoteDisplayStatus();
}
catch (RemoteException e) {
}
applyState();
}
private void applyState() {
final int featureState = mWifiDisplayStatus.getFeatureState();
mActionBarSwitch.setEnabled(featureState != WifiDisplayStatus.FEATURE_STATE_DISABLED);
mActionBarSwitch.setChecked(mWifiDisplayOnSetting);
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.removeAll();
if (featureState == WifiDisplayStatus.FEATURE_STATE_ON) {
final WifiDisplay[] pairedDisplays = mWifiDisplayStatus.getRememberedDisplays();
final WifiDisplay[] availableDisplays = mWifiDisplayStatus.getAvailableDisplays();
final WifiDisplay[] pairedRemoteDisplays = mRemoteDisplayStatus.getRememberedDisplays();
final WifiDisplay[] availableRemoteDisplays = mRemoteDisplayStatus.getAvailableDisplays();
mDisableHDCP = new CheckBoxPreference(getActivity().getApplicationContext());
mDisableHDCP.setTitle(R.string.pref_wifi_disable_hdcp_title);
mDisableHDCP.setSummary(R.string.pref_wifi_disable_hdcp_summary);
mDisableHDCP.setChecked(Integer.parseInt(SystemProperties.get(DISABLE_HDCP_​PREF, "0")) != 0);
mDisableHDCP.setOrder(0);
preferenceScreen.addPreference(mDisableHDCP);
if (mPairedDevicesCategory == null) {
mPairedDevicesCategory = new PreferenceCategory(getActivity());
mPairedDevicesCategory.setTitle(R.string.wifi_display_paired_devices);
} else {
mPairedDevicesCategory.removeAll();
}
mPairedDevicesCategory.setOrder(1);
preferenceScreen.addPreference(mPairedDevicesCategory);
for (WifiDisplay d : pairedDisplays) {
mPairedDevicesCategory.addPreference(createWifiDisplayPreference(d, true, false));
}
for (WifiDisplay d : pairedRemoteDisplays) {
if (d.isHidden()) {
continue;
}
mPairedDevicesCategory.addPreference(createWifiDisplayPreference(d, true, true));
}
if (mPairedDevicesCategory.getPreferenceCount() == 0) {
preferenceScreen.removePreference(mPairedDevicesCategory);
}
if (mAvailableDevicesCategory == null) {
mAvailableDevicesCategory = new ProgressCategory(getActivity(), null,
R.string.wifi_display_no_devices_found);
mAvailableDevicesCategory.setTitle(R.string.wifi_display_available_devices)​;
} else {
mAvailableDevicesCategory.removeAll();
}
mAvailableDevicesCategory.setOrder(2);
preferenceScreen.addPreference(mAvailableDevicesCategory);
for (WifiDisplay d : availableDisplays) {
if (!contains(pairedDisplays, d.getDeviceAddress())) {
mAvailableDevicesCategory.addPreference(createWifiDisplayPreference(d, false, false));
}
}
for (WifiDisplay d : availableRemoteDisplays) {
if (!contains(pairedRemoteDisplays, d.getDeviceAddress())
&& !(d.getDeviceName().startsWith("hidden:"))) {
mAvailableDevicesCategory.addPreference(createWifiDisplayPreference(d, false, true));
}
}
if (mWifiDisplayStatus.getScanState() == WifiDisplayStatus.SCAN_STATE_SCANNING ||
mRemoteDisplayStatus.getScanState() == WifiDisplayStatus.SCAN_STATE_SCANNING) {
mAvailableDevicesCategory.setProgress(true);
} else {
mAvailableDevicesCategory.setProgress(false);
}
} else {
mEmptyView.setText(featureState == WifiDisplayStatus.FEATURE_STATE_OFF ?
R.string.wifi_display_settings_empty_list_wifi_display_off :
R.string.wifi_display_settings_empty_list_wifi_display_disabled);
}
getActivity().invalidateOptionsMenu();
}
private void autoConnect() {
final int featureState = mWifiDisplayStatus.getFeatureState();
/** mActionBarSwitch.setEnabled(featureState != WifiDisplayStatus.FEATURE_STATE_DISABLED);
mActionBarSwitch.setChecked(mWifiDisplayOnSetting);
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.removeAll(); */
if (featureState == WifiDisplayStatus.FEATURE_STATE_ON) {
final WifiDisplay[] pairedDisplays = mWifiDisplayStatus.getRememberedDisplays();
final WifiDisplay[] availableDisplays = mWifiDisplayStatus.getAvailableDisplays();
final WifiDisplay[] pairedRemoteDisplays = mRemoteDisplayStatus.getRememberedDisplays();
final WifiDisplay[] availableRemoteDisplays = mRemoteDisplayStatus.getAvailableDisplays();
/** mDisableHDCP = new CheckBoxPreference(getActivity().getApplicationContext());
mDisableHDCP.setTitle(R.string.pref_wifi_disable_hdcp_title);
mDisableHDCP.setSummary(R.string.pref_wifi_disable_hdcp_summary);
mDisableHDCP.setChecked(Integer.parseInt(SystemProperties.get(DISABLE_HDCP_​PREF, "0")) != 0);
mDisableHDCP.setOrder(0);
preferenceScreen.addPreference(mDisableHDCP);
if (mPairedDevicesCategory == null) {
mPairedDevicesCategory = new PreferenceCategory(getActivity());
mPairedDevicesCategory.setTitle(R.string.wifi_display_paired_devices);
} else {
mPairedDevicesCategory.removeAll();
}
mPairedDevicesCategory.setOrder(1);
preferenceScreen.addPreference(mPairedDevicesCategory); */
/** for (WifiDisplay d : pairedDisplays) {
mPairedDevicesCategory.addPreference(createWifiDisplayPreference(d, true, false));
}
for (WifiDisplay d : pairedRemoteDisplays) {
if (d.isHidden()) {
continue;
}
mPairedDevicesCategory.addPreference(createWifiDisplayPreference(d, true, true));
}
if (mPairedDevicesCategory.getPreferenceCount() == 0) {
preferenceScreen.removePreference(mPairedDevicesCategory);
}
if (mAvailableDevicesCategory == null) {
mAvailableDevicesCategory = new ProgressCategory(getActivity(), null,
R.string.wifi_display_no_devices_found);
mAvailableDevicesCategory.setTitle(R.string.wifi_display_available_devices)​;
} else {
mAvailableDevicesCategory.removeAll();
}
mAvailableDevicesCategory.setOrder(2);
preferenceScreen.addPreference(mAvailableDevicesCategory); */
for (WifiDisplay d : availableDisplays) {
/** if (!contains(pairedDisplays, d.getDeviceAddress())) {
mAvailableDevicesCategory.addPreference(createWifiDisplayPreference(d, false, false));
} */
// JOK check if there is an existing connection
boolean isActive = false;
isActive = d.equals(mWifiDisplayStatus.getActiveDisplay());
// JOK only connect, if there is no existing connection
if (!isActive) {
mDisplayManager.connectWifiDisplay(d.getDeviceAddress());
}
}
for (WifiDisplay d : availableRemoteDisplays) {
/** if (!contains(pairedRemoteDisplays, d.getDeviceAddress())
&& !(d.getDeviceName().startsWith("hidden:"))) {
mAvailableDevicesCategory.addPreference(createWifiDisplayPreference(d, false, true));
} */
// JOK check if there is an existing connection
boolean isActive = false;
isActive = d.equals(mRemoteDisplayStatus.getActiveDisplay());
// JOK only connect, if there is no existing connection
if (!isActive) {
try {
mRemoteDisplayAdapter.connectRemoteDisplay(d.getDeviceAddress());
}
catch (RemoteException e) {
}
}
}
/** if (mWifiDisplayStatus.getScanState() == WifiDisplayStatus.SCAN_STATE_SCANNING ||
mRemoteDisplayStatus.getScanState() == WifiDisplayStatus.SCAN_STATE_SCANNING) {
mAvailableDevicesCategory.setProgress(true);
} else {
mAvailableDevicesCategory.setProgress(false);
}
} else {
mEmptyView.setText(featureState == WifiDisplayStatus.FEATURE_STATE_OFF ?
R.string.wifi_display_settings_empty_list_wifi_display_off :
R.string.wifi_display_settings_empty_list_wifi_display_disabled); */
}
//getActivity().invalidateOptionsMenu();
}
private Preference createWifiDisplayPreference(final WifiDisplay d, boolean paired, boolean isRemote) {
WifiDisplayPreference p = new WifiDisplayPreference(getActivity(), d, isRemote);
WifiDisplayStatus displayStatus = null;
if (isRemote) {
displayStatus = mRemoteDisplayStatus;
} else {
displayStatus = mWifiDisplayStatus;
}
if (d.equals(displayStatus.getActiveDisplay())) {
switch (displayStatus.getActiveDisplayState()) {
case WifiDisplayStatus.DISPLAY_STATE_CONNECTED:
p.setSummary(R.string.wifi_display_status_connected);
break;
case WifiDisplayStatus.DISPLAY_STATE_CONNECTING:
p.setSummary(R.string.wifi_display_status_connecting);
break;
}
} else if (paired && contains(displayStatus.getAvailableDisplays(),
d.getDeviceAddress())) {
p.setSummary(R.string.wifi_display_status_available);
}
if (paired) {
p.setWidgetLayoutResource(R.layout.wifi_display_preference);
}
return p;
}
private void showDisconnectDialog(final WifiDisplay display, final boolean isRemoteDisplay) {
DialogInterface.OnClickListener ok = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (!isRemoteDisplay && display.equals(mWifiDisplayStatus.getActiveDisplay())) {
mDisplayManager.disconnectWifiDisplay();
} else if (isRemoteDisplay && display.equals(mRemoteDisplayStatus.getActiveDisplay())) {
try {
mRemoteDisplayAdapter.disconnectRemoteDisplay();
}
catch (RemoteException e) {
}
}
}
};
AlertDialog dialog = new AlertDialog.Builder(getActivity())
.setCancelable(true)
.setTitle(R.string.wifi_display_disconnect_title)
.setMessage(Html.fromHtml(getResources().getString(
R.string.wifi_display_disconnect_text, display.getFriendlyDisplayName())))
.setPositiveButton(android.R.string.ok, ok)
.setNegativeButton(android.R.string.cancel, null)
.create();
dialog.show();
}
private void showOptionsDialog(final WifiDisplay display, final boolean isRemoteDisplay) {
View view = getActivity().getLayoutInflater().inflate(R.layout.wifi_display_options, null);
final EditText nameEditText = (EditText)view.findViewById(R.id.name);
nameEditText.setText(display.getFriendlyDisplayName());
DialogInterface.OnClickListener done = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String name = nameEditText.getText().toString().trim();
if (name.isEmpty() || name.equals(display.getDeviceName())) {
name = null;
}
if (!isRemoteDisplay) {
mDisplayManager.renameWifiDisplay(display.getDeviceAddress(), name);
} else {
try {
mRemoteDisplayAdapter.renameRemoteDisplay(display.getDeviceAddress(), name);
}
catch (RemoteException e) {
}
}
}
};
DialogInterface.OnClickListener forget = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (!isRemoteDisplay) {
mDisplayManager.forgetWifiDisplay(display.getDeviceAddress());
} else {
try {
mRemoteDisplayAdapter.forgetRemoteDisplay(display.getDeviceAddress());
}
catch (RemoteException e) {
}
}
}
};
AlertDialog dialog = new AlertDialog.Builder(getActivity())
.setCancelable(true)
.setTitle(R.string.wifi_display_options_title)
.setView(view)
.setPositiveButton(R.string.wifi_display_options_done, done)
.setNegativeButton(R.string.wifi_display_options_forget, forget)
.create();
dialog.show();
}
private static boolean contains(WifiDisplay[] displays, String address) {
for (WifiDisplay d : displays) {
if (d.getDeviceAddress().equals(address)) {
return true;
}
}
return false;
}
private final CompoundButton.OnCheckedChangeListener mSwitchOnCheckedChangedListener =
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mWifiDisplayOnSetting = isChecked;
Settings.Global.putInt(getContentResolver(),
Settings.Global.WIFI_DISPLAY_ON, isChecked ? 1 : 0);
}
};
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED)) {
WifiDisplayStatus status = (WifiDisplayStatus)intent.getParcelableExtra(
DisplayManager.EXTRA_WIFI_DISPLAY_STATUS);
mWifiDisplayStatus = status;
applyState();
// JOK auto connect
autoConnect();
} else if (action.equals(DisplayManager.ACTION_REMOTE_DISPLAY_STATUS_CHANGED)) {
WifiDisplayStatus status = (WifiDisplayStatus)intent.getParcelableExtra(
DisplayManager.EXTRA_REMOTE_DISPLAY_STATUS);
mRemoteDisplayStatus = status;
applyState();
// JOK auto connect
autoConnect();
}
}
};
private final ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange, Uri uri) {
update();
}
};
private final class WifiDisplayPreference extends Preference
implements View.OnClickListener {
private final WifiDisplay mDisplay;
private final boolean mIsRemoteDisplay;
public WifiDisplayPreference(Context context,
WifiDisplay display, boolean isRemoteDisplay) {
super(context);
mDisplay = display;
mIsRemoteDisplay = isRemoteDisplay;
setTitle(display.getFriendlyDisplayName());
}
public WifiDisplay getDisplay() {
return mDisplay;
}
public boolean isRemoteDisplay() {
return mIsRemoteDisplay;
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
ImageView deviceDetails = (ImageView) view.findViewById(R.id.deviceDetails);
if (deviceDetails != null) {
deviceDetails.setOnClickListener(this);
if (!isEnabled()) {
TypedValue value = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.disabledAlpha,
value, true);
deviceDetails.setImageAlpha((int)(value.getFloat() * 255));
}
}
}
@Override
public void onClick(View v) {
showOptionsDialog(mDisplay, mIsRemoteDisplay);
}
}
}

Categories

Resources