Skip to content

Commit

Permalink
ip reporting issue in pc receiver fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs20 committed Jul 14, 2017
1 parent 76f1644 commit 9c3a80b
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.wolandsoft.sss"
minSdkVersion 23
targetSdkVersion 25
versionCode 24
versionName '1.4.0.24'
versionCode 25
versionName '1.4.1.25'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
*/
public class PairedDevicesFragment extends Fragment
implements AlertDialogFragment.OnDialogToFragmentInteract{
private static final int PROTOCOL_VER = 1;
private final static String ARG_POSITION = "position";
private static final int DELETE_PAIRED_DEVICE_CONFIRMATION_DIALOG = 1;
private RecyclerViewAdapter mRecyclerViewAdapter;
Expand Down Expand Up @@ -189,6 +190,11 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
byte[] packet = Base64.decode(encodedB64, Base64.DEFAULT);
ByteArrayInputStream bais = new ByteArrayInputStream(packet);
DataInputStream dis = new DataInputStream(bais);
int ver = dis.readInt();
if(ver != PROTOCOL_VER){
Toast.makeText(getContext(), getString(R.string.message_invalid_receiver), Toast.LENGTH_LONG).show();
return;
}
long crc = dis.readLong();
int size = dis.readInt();
byte[] payload = new byte[size];
Expand All @@ -199,6 +205,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (checksum.getValue() == crc) {
bais = new ByteArrayInputStream(payload);
dis = new DataInputStream(bais);
size = dis.readInt();
device.mIp = new byte[size];
dis.readFully(device.mIp, 0, size);
device.mPort = dis.readInt();
size = dis.readInt();
payload = new byte[size];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@

import com.wolandsoft.sss.R;
import com.wolandsoft.sss.service.pccomm.PairedDevice;
import com.wolandsoft.sss.util.LogEx;
import com.wolandsoft.sss.service.pccomm.PairedDevices;
import com.wolandsoft.sss.util.LogEx;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**s
/**
* s
* Adapter for {@link RecyclerView} component.
*/
abstract class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewHolder> {
Expand All @@ -46,7 +50,13 @@ public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public void onBindViewHolder(RecyclerViewHolder holder, int position) {
holder.itemView.setLongClickable(true);
final PairedDevice device = mDevices.get(position);
holder.mTxtTitle.setText(device.mHost + ":" + device.mPort);
holder.mTxtTitle.setText(device.mHost);
String ip = "?";
try {
ip = InetAddress.getByAddress(device.mIp).getHostAddress();
} catch (UnknownHostException ignore) {
}
holder.mTxtTitleSmall.setText(ip + ":" + device.mPort);
}

@Override
Expand All @@ -60,7 +70,7 @@ void deleteItem(int idx) {
notifyItemRemoved(idx);
}

public PairedDevices getModel(){
public PairedDevices getModel() {
return mDevices;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
*/
public class RecyclerViewHolder extends RecyclerView.ViewHolder {
final TextView mTxtTitle;
final TextView mTxtTitleSmall;

RecyclerViewHolder(View view) {
super(view);
mTxtTitle = (TextView) view.findViewById(R.id.txtTitle);
mTxtTitleSmall = (TextView) view.findViewById(R.id.txtTitleSmall);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public PairedDevice[] newArray(int size) {
return new PairedDevice[size];
}
};
public byte[] mIp;
public String mHost;
public int mPort;
public byte[] mKey;
Expand All @@ -41,6 +42,8 @@ public PairedDevice() {
}

private PairedDevice(Parcel in) {
mIp = new byte[in.readInt()];
in.readByteArray(mIp);
mHost = in.readString();
mPort = in.readInt();
mKey = new byte[in.readInt()];
Expand All @@ -54,6 +57,8 @@ public int describeContents() {

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mIp.length);
dest.writeByteArray(mIp);
dest.writeString(mHost);
dest.writeInt(mPort);
dest.writeInt(mKey.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.json.JSONObject;

import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -71,7 +72,7 @@ protected void onHandleIntent(Intent intent) {
}
byte[] cipherTextBuff = aesCipher.cipher(jsonObj.toString().getBytes(StandardCharsets.UTF_8));
try (Socket client = new Socket()) {
client.connect(new InetSocketAddress(device.mHost, device.mPort), getResources().getInteger(R.integer.pref_paired_device_connect_timeout));
client.connect(new InetSocketAddress(InetAddress.getByAddress(device.mIp), device.mPort), getResources().getInteger(R.integer.pref_paired_device_connect_timeout));
OutputStream outStream = client.getOutputStream();
outStream.write(cipherTextBuff);
outStream.flush();
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/layout/fragment_pairs_include_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
android:contentDescription="@string/label_logo"
app:srcCompat="@mipmap/img24dp_pc" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
Expand All @@ -46,5 +51,15 @@
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/txtTitleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="1dp"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

</LinearLayout>
</android.support.v7.widget.CardView>
2 changes: 1 addition & 1 deletion app/src/main/res/values/preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<item name="pref_permission_asked_type_key" translatable="false" type="string">permission_asked_type</item>

<item name="pref_paired_devices_key" translatable="false" type="string">paired_devices</item>
<item name="pref_paired_devices_key" translatable="false" type="string">stored_paired_devices</item>
<item name="pref_open_paired_devices_key" translatable="false" type="string">open_paired_devices</item>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<string name="message_pc_receivers">List of devices you can copy data to.</string>
<string name="message_scan_receiver_code">Open PC Receiver\'s QR code and scan it.</string>
<string name="message_invalid_qr_code">Invalid QR Code.</string>
<string name="message_invalid_receiver">Incompatible Receiver Version.</string>

<string name="label_privacy_policy">Privacy Policy</string>
<string name="message_privacy_policy">Sensitive permissions usage</string>
Expand Down

0 comments on commit 9c3a80b

Please sign in to comment.